启动MySQL后root无法登陆
[root@localhost mysql]# /usr/bin/mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决办法:
1.停止MySQL
[root@localhost mysql]# service mysql stop
2.启动MySQL安全模式
[root@localhost mysql]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -u root mysql
3.更改root密码
mysql> UPDATE user SET Password=PASSWORD('sa') where USER='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
4.重新登录后,无法执行show databases;
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
5.重新设置密码
mysql> SET PASSWORD = PASSWORD('sa');
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
--转自