-root ~]$ mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
[[email protected] ~]$ mysql -uroot -p
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password(’123123′) where user=’root’;
Query OK, 0 rows affected (0.02 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> SHOW GRANTS FOR root\G
*************************** 1. row ***************************
Grants for [email protected]%: GRANT USAGE ON *.* TO ‘root’@‘%’ IDENTIFIED BY PASSWORD ‘*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1′
*************************** 2. row ***************************
Grants for [email protected]%: GRANT ALL PRIVILEGES ON root_master
.* TO ‘root’@‘%’
2 rows in set (0.00
mysql> select user,host,password from mysql.user order by user,host;
+————-+—————+——————————————-+
| user | host | password |
+————-+—————+——————————————-+
| | bj-root | |
| | localhost | |
| root | % | *E56A114692FE0DE073F9A1DD68A00EEB9703F3F1 |
| root | 127.0.0.1 | *B335B8949A6AF011EA3D9F37F046C6E413BC23FB |
| root | ::1 | |
| root | bj-root | |
| root | localhost | *B335B8949A6AF011EA3D9F37F046C6E413BC23FB |
| weixin_user | % | *DF81D3DE3ABC1508BFB0F1D4DE9C2EECBAE43E4F |
| weixinuser | % | *DF81D3DE3ABC1508BFB0F1D4DE9C2EECBAE43E4F |
+————-+—————+——————————————-+
9 rows in set (0.00 sec)
解决方法,删除为空的用户授权:
mysql>
mysql>
mysql> drop user ”@’localhost’;
Query OK, 0 rows affected (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ”@’bj-root′;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> select user,host,password from mysql.user order by user,host;
+————-+—————+——————————————-+
| user | host | password |
+————-+—————+——————————————-+
| admin | % | |
| root | % | *E56A114692FE0DE073F9A1DD68A00EEB9703F3F1 |
| root | 127.0.0.1 | *B335B8949A6AF011EA3D9F37F046C6E413BC23FB |
| root | ::1 | |
| root | bj-root | |
| root | localhost | *B335B8949A6AF011EA3D9F37F046C6E413BC23FB |
| weixin_user | % | *DF81D3DE3ABC1508BFB0F1D4DE9C2EECBAE43E4F |
| weixinuser | % | *DF81D3DE3ABC1508BFB0F1D4DE9C2EECBAE43E4F |
+————-+—————+——————————————-+
8 rows in set (0.00 sec)
原因是因为有mysql库的user表有空值的情况mysql进行认证的时候,匹配都了空值,所以就直接能进入myql里面了。