CentOS 7-MySQL无root密码的情况下,命令行重置root密码

顺序执行如下指令即可重置root的密码,其他可以举一反三。
CentOS 7的MySQL不像之前直接启动mysql_safe即可,但其实方式是一样的。

systemctl stop mysqld
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
systemctl start mysqld
mysql -u root
UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword') WHERE User = 'root' AND Host = 'localhost';
quit
systemctl stop mysqld
systemctl unset-environment MYSQLD_OPTS
systemctl start mysqld
mysql -u root -p

方法完整来自:http://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7#answer-34207996


未经允许不得转载:阿藏博客 » CentOS 7-MySQL无root密码的情况下,命令行重置root密码