linux下mysql 使用mysql -uroot -p输入密码无法登录问题的解决

1.停止当前mysql服务

/etc/init.d/mysqld stop 或  service mysqld stop

(把stop换为status可查看当前状态)

2.以--skip-grant-tables 选项启动mysql

mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 

(如果运行此语句没有回到上一级shell,另外打开一个终端继续执行以下步骤即可)

3.登录

mysql -u root mysql 

 4.修改登录密码:修改yourPassword处即可

mysql> UPDATE user SET Password=PASSWORD('yourPassword') where USER='root'; 
mysql> FLUSH PRIVILEGES; 
mysql> exit

                

 

posted on 2017-04-27 14:04  梓明  阅读(768)  评论(0编辑  收藏  举报