1、mysql5.7.20 下载地址
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
2、移除mariadb组件,新建mysql组和用户
yum -y remove mariadb-libs
groupadd mysql
useradd mysql -g mysql -s /sbin/nologin
3、解压mysql二进制包并移动/opt/
tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.20-linux-glibc2.12-x86_64 /opt/mysql5.7
4、添加环境mysql变量到/etc/profile并加载
export PATH=$PATH:/opt/mysql5.7/bin
source /etc/profile
5、建立mysql data数据目录并授权
mkdir /opt/mysql5.7/data
chown -R mysql.mysql /opt/mysql5.7
6、初始化数据(建库)
mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql5.7/ --datadir=/opt/mysql5.7/data/
mysqld --initialize --user=mysql --basedir=/opt/mysql5.7/ --datadir=/opt/mysql5.7/data/
--initialize-insecure:空密码
--initialize:生成随机密码
7、创建默认配置文件
[root@53 data]# cat /etc/my.cnf
[mysqld]
user=mysql
datadir=/opt/mysql5.7/data
basedir=/opt/mysql5.7/
port=3306
server_id=2
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>
注:根据实际情况增加相关配置!
8、使用systemd管理mysql
[root@53 data]# cat /etc/systemd/system/mysqld.service
Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql5.7/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
注:根据实际情况修改ExecStart
9、启动
systemctl start mysqld
systemctl start/stop/restart/status mysqld
10、使用mysqladmin 修改管理员密码
mysqladmin -uroot -p password 123456