MySQL mysqld_safe登录更改用户密码和解决本地localhost不能登录

忘记MySQL密码或者本地lcoalhost,root用户无法登录时。可用以下方法无密码登录

1 /etc/init.d/mysqld stop  关闭mysqld服务 (可以直接killall mysqld)

2 mysqld_safe --skip-grant-tables &

3 mysql 登录

4 更改mysql用户密码:update mysql.user set password=password("123456") where user=root and host=localhost;

5 flush privileges;ss

6 quit退出

7 重启mysqld服务  /etc/init.d/mysqld restart

8 测试修改后密码登录

本地lcoalhost,root用户无法登录

1 /etc/init.d/mysqld stop  关闭mysqld服务 (可以直接killall mysqld)

2 mysqld_safe --skip-grant-tables &

3 mysql 登录

4 查看mysql.user表root用户host字段是否有localhost值。如果没有需加上

5 退出重启mysqld服务

6 测试登录,如果还无法登录则有可能没有授权localhost登录

7 使用mysql -uroot -h127.0.0.1 -p登录并授权localhost本地root登录

8 测试登录




猜你喜欢

转载自blog.csdn.net/crazy_brick/article/details/80308533
今日推荐