采坑Mysql之ROOT用户无法登陆

/ 0评 / 1

mysql好久没用了,最近在服务器里装了一个,改了root密码后,竟然无法登陆,以为是密码记错了,只好进入safe模式更改

$ killall -TERM mysqld
$ mysqld_safe --skip-grant-tables;
$ mysql -u root
mysql> use mysql;
mysql> update user set password="yourpassword" where user="root";
mysql> flush privileges;

这下可好,改了以后还是无法进入,接着看到调试信息中出现localhost can not connect to mysql server 好吧,大概知道是怎么回事了,删除ROOT用户重新添加一个

mysql> use mysql;
mysql> drop user ‘root’@’localhost’; 
mysql> flush privileges;
mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'yourpassword';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

好了,登录一切正常。 以后记住,不要直接改密码,请用Mysql自带配置更改

mysql_secure_installation

感谢:家住梅秀路的热心网友

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

*

code