centos下安装MySQL5.7

时间:2023-02-07 19:54:49

1.查找mysql
whereis mysql

2.删除mysql
yum remove mysql mysql-server mysql-libs mysql-server;
rm –rf /usr/lib64/mysql
rm –rf /etc/my.cnf
rm -rf /root/.mysql_sercret
rm -rf /var/log/mysqld.log
rm -rf /var/lib/mysql (如果这个目录如果不删除,再重新安装之后,密码还是之前的密码,不会重新初始化!)

3.下载属于自己的rpm
http://dev.mysql.com/downloads/repo/yum/

4.安装刚才下载的rpm
yum install mysql57-community-release-el6-7.noarch.rpm

5.安装mysql
yum install mysql-community-server

6.启动mysql(此时会进行初始化,生成随机密码)
service mysqld start

7.获取随机密码
sudo grep 'temporary password' /var/log/mysqld.log

8.更新root密码(字母大小写+数字)
/usr/bin/mysql_secure_installation

9.启动mysql
mysql -u root -p

10.更新root权限(开启远程访问)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyPassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;

11.如过还想更改密码(不再是password字段了)
use mysql;
update mysql.user set authentication_string=password('Kane_2015') where user='root';

12.重启mysql服务才能使密码更改生效
service mysqld restart