二进制部署MySQL5.7

开始部署
1、优先卸载mariadb,如果没有可忽略
[root@mysql ~]# yum -y erase mariadb
[root@mysql ~]# rpm -e qt-mysql-4.8.7-2.el7.x86_64 --nodeps

2、部署mysql 5.7

[root@mysql ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@mysql ~]# tar zxf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 
[root@mysql ~]# mv mysql-5.7.22-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@mysql ~]# ln -s /usr/local/mysql/bin/* /usr/local/bin/

3、编辑配置文件并初始化MySQL

[root@mysql ~]# rm -rf /etc/my.cnf
[root@mysql ~]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
log-error=/usr/local/mysql/data/mysql.err
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock
#创建所需目录及用户并更改属主
[root@mysql ~]# mkdir -p /usr/local/mysql/data
[root@mysql ~]# useradd -M -s /sbin/nologin mysql
[root@mysql ~]# chown -R mysql:mysql /usr/local/mysql/
#初始化MySQL
[root@mysql ~]# mysqld --initialize --user mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
[root@mysql ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysql ~]# chkconfig --add mysqld
#启动并设置为开机自启
[root@mysql ~]# systemctl enable mysqld
[root@mysql ~]# systemctl start mysqld
[root@mysql ~]# netstat -anput | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      3441/mysqld       

4、修改MySQL的root用户初始密码

[root@mysql ~]# mysqlpwd=`cat /usr/local/mysql/data/mysql.err | grep password |awk -F‘root@localhost: ‘ ‘{print $2}‘`
[root@mysql ~]# mysql -uroot -p${mysqlpwd} -e ‘alter user root@localhost identified by "123.com"‘ --connect-expired-password
[root@mysql ~]# mysql -uroot -p123.com

二进制部署MySQL5.7

上一篇:MySQL各种错误代码解决方式(不定期更新)


下一篇:SQL注入