mysql 5.7安装

基础环境:centos7.9

创建日志存放目录

复制代码
mkdir -p /opt/supervisor/log

安装相关工具

复制代码
yum install -y perl net-tools numactl gcc python-devel

配置yum源

复制代码
sudo vim /etc/yum.repos.d/mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

 sudo vim /etc/yum.repos.d/mysql-community-source.repo
[mysql-connectors-community-source]
name=MySQL Connectors Community - Source
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community-source]
name=MySQL Tools Community - Source
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql55-community-source]
name=MySQL 5.5 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql56-community-source]
name=MySQL 5.6 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community-source]
name=MySQL 5.7 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview-source]
name=MySQL Tools Preview - Source
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

清除yum缓存,并且重新缓存

复制代码
sudo yum clean all
sudo yum makecache

卸载自带的mariadb

复制代码
sudo yum remove mariadb-libs.x86_64 -y

安装mysql5.7

复制代码
sudo yum install mysql-common -y
sudo yum install mysql-server -y

修改mysql配置文件

复制代码
sudo vim /etc/my.cnf
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
bind-address = 0.0.0.0
port = 3306
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
vim /etc/supervisord/conf.d/mysql.conf
[program:mysql]
command=/usr/sbin/mysqld  --defaults-file=/etc/my.cnf
numprocs=1
user=mysql
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/mysqld.log
stdout_logfile_maxbytes=200MB
stdout_logfile_backups=20

注意!!!

一定要先初始化数据库,在启动数据库!

如果没有初始化就先启动了数据库,那必须要rm -rf /var/lib/mysql/*,也就是my.cnf里所配置的datadir的路径。

初始化数据库

复制代码
mysqld --initialize >/var/log/mysql_init.log 2>&1

找到其初始密码

复制代码
grep "password" /var/log/mysql_init.log

第一次登陆必须先修改密码!!

启动数据库,配置开机自启

复制代码
sudo systemctl start mysqld
sudo systemctl enable mysqld

登陆数据库

bash 复制代码
mysql -uroot -h127.0.01 -p

#查看数据库是否开启二进制日志

复制代码
show variables like '%log_bin%';

初始化配置,给root用户配置密码

复制代码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NS6ImYNKRFrVWTlb';

flush privileges;
相关推荐
kerli1 小时前
Android 嵌套滑动设计思想
android·客户端
Olrookie1 小时前
若依前后端分离版学习笔记(三)——表结构介绍
笔记·后端·mysql
恣艺2 小时前
LeetCode 854:相似度为 K 的字符串
android·算法·leetcode
阿华的代码王国2 小时前
【Android】相对布局应用-登录界面
android·xml·java
用户207038619493 小时前
StateFlow与SharedFlow如何取舍?
android
QmDeve3 小时前
原生Android Java调用系统指纹识别方法
android
淹没3 小时前
🚀 告别复杂的HTTP模拟!HttpHook让Dart应用测试变得超简单
android·flutter·dart
Lemon程序馆3 小时前
今天聊聊 Mysql 的那些“锁”事!
后端·mysql