Linux下mysql数据库root无法登录的情况

今天安装lnmp环境后用mysql -u root -p连接密码后出现错误

Access denied for user 'root'@'localhost' (using password: YES)
然后我就用 /etc/init.d/mysql stop 先去停止数据库
然后用安全模式 mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 进入数据库
然后用SQL语句修改root权限 UPDATE user SET Password=PASSWORD('我的密码') where USER='root';
改完了后 重新刷新权限 FLUSH PRIVILEGES; 然后quit退出
然后重启数据库就行了 /etc/init.d/mysql restart
[root@967b0e11e627 default]# mysql -u root -p
Enter password:
ERROR (): Access denied for user 'root'@'localhost' (using password: YES)
[root@967b0e11e627 default]# /etc/init.d/mysql stop
Shutting down MySQL. SUCCESS!
[root@967b0e11e627 default]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[]
[root@967b0e11e627 default]# :: mysqld_safe Logging to '/usr/local/mysql/var/967b0e11e627.err'.
:: mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var [root@967b0e11e627 default]# mysql -u root mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.5.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
rows in set (0.02 sec) mysql> UPDATE user SET Password=PASSWORD('Weiwend&20150125') where USER='root';
Query OK, rows affected (0.00 sec)
Rows matched: Changed: Warnings: mysql> FLUSH PRIVILEGES;
Query OK, rows affected (0.00 sec) mysql> quit
Bye
[root@967b0e11e627 default]# /etc/init.d/mysql restart
Shutting down MySQL. :: mysqld_safe mysqld from pid file /usr/local/mysql/var/967b0e11e627.pid ended
SUCCESS!
Starting MySQL.. SUCCESS!
[]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@967b0e11e627 default]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.5.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
rows in set (0.00 sec) mysql> exit
Bye
上一篇:html5\CSS3有哪些新特性、移除了哪些元素?如何处理HTML5新标签的浏览器兼容问题?如何区分HTML和HTML5?


下一篇:ElasticSearch安装和head插件安装