CentOS7下安装MySQL5.7

时间:2023-01-18 21:08:18

环境:CentOS7、mysql-5.7.17

1、软件下载

在MySQL官网下载mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar

2、解压

tar -xvf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar

mkdir mysql

mv mysql-community*.rpm mysql

3、卸载mariadb

rpm -qa | grep mariadb

rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

4、安装MySQL

rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm 
rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm 
rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm 
rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm

5、设置密码

vi /etc/my.cnf

[mysqld]之后添加
skip-grant-tables

service mysqld start

mysql -uroot

>update mysql.user set authentication_string=password('123456') where user='root' ;

>flush privileges;

>exit;

service mysqld stop

vi /etc/my.cnf

删除skip-grant-tables

service mysqld start

mysql -uroot -p123456

>set global validate_password_policy=0;

>set global validate_password_length=1;

>set global validate_password_mixed_case_count=2;

>set password = password('123456');

>exit;

6、开启远程登录

mysql -uroot -p123456

>GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION; 

>FLUSH PRIVILEGES;