CentOS6.4下安装MySQL5.6.10后root无法登陆MySQL

原文转自:http://libin580.blog.51cto.com/2252719/1142588

 启动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
Bye

 
    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)

 

你可能感兴趣的:(CentOS6.4下安装MySQL5.6.10后root无法登陆MySQL)