mysqldump -u username -h host -P 3306 -p --all-databases > databases.sql
sudo service mysqld stop
sudo rpm -qa | grep mysql
sudo yum remove mysql mysql-*
sudo yum list installed | grep mysql
查找分散mysql文件夹(有必要的话进行删除)
sudo find / -name mysql
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
yum repolist all | grep mysql
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
sudo yum install mysql-community-server
sudo vim /etc/my.cnf
在mysqld字段下添加utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
sudo service mysqld start
如果启动失败,error日志内报如下错误
[ERROR] Fatal error: mysql.user table is damaged. Please run mysql_upgrade.
就在/etc/my.cnf添加skip-grant-tables
全新安装mysql5.7可不执行
sudo mysql_upgrade -u root -p
全新安装需要先从mysql错误日志中获取临时root密码
grep 'temporary password' /var/log/mysqld.log
期间会问你是否要安装密码安全插件和移除test库和匿名用户和设置root密码
sudo /usr/bin/mysql_secure_installation
如果不想使用复杂密码(开发环境),可以root登录后卸载密码安全插件
mysql> UNINSTALL PLUGIN validate_password;
再执行上面的mysql_secure_installation修改root密码即可
mysql -u username -h host -p -P 3306 < databases.sql
5.7之后的mysql使用了新的密码验证机制,并且password字段也更改为了authentication_string,因此需要重新设置已存在的用户密码
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('newpwd') WHERE Host = 'some_host' AND User = 'some_user';
mysql> FLUSH PRIVILEGES;
sudo service mysqld restart