ERROR 1133 (42000): Can't find any matching row in the user table
1、問題描述
使用
set password for 'root'@'localhost'=password('MyNewPass4!');
命令修改mysql
數據庫root
用戶密碼提示**ERROR 1133 (42000): Can't find any matching row in the user table
**錯誤
2、主要原因
-
錯誤提示的字面意思:
在用戶表中找不到任何匹配的行
-
登錄
mysql
執行以下命令
use mysql; select Host,User from user;
- 1
主要原因是修改密碼的條件不否
3、解決辦法
- 將
set password for 'root'@'localhost'=password('MyNewPass4!');
代碼中的localhost
修改%
,與數據庫Host
字段值一致
set password for 'root'@'%'=password('MyNewPass4!');
- 刷新
flush privileges;
===================================================================================================================
自我測試案例如下 :
因為在客戶端進行連接的時候沒有權限,報錯如下:
在進行授權的時候發現 報錯 1133,如下所示。
[root@localhost][mysql]> grant all privileges on *.* to 'root'@'%' with grant option; ERROR 1133 (42000): Can't find any matching row in the user table
這是因為,在授權進行授權的時候 ,需要讀取 mysql.user 表中的記錄。如果沒有 ‘root’@'%' 這條記錄,那么就不能授權,如下所示
[root@localhost][mysql]> select Host,User from user; +----------------+---------------+ | Host | User | +----------------+---------------+ | 192.168.17.182 | repl | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +----------------+---------------+ 4 rows in set (0.00 sec)
那么需要進行 增加用戶的操作:
[root@localhost][mysql]> create user 'root'@'%' identified by '123456'; Query OK, 0 rows affected (0.00 sec)
然后我們再來查詢 mysql.user 的記錄,可以發現有了 ‘root’@'%' 這條記錄 :
[root@localhost][mysql]> select host,user from user; +----------------+---------------+ | host | user | +----------------+---------------+ | % | root | | 192.168.17.182 | repl | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +----------------+---------------+ 5 rows in set (0.00 sec)
下面再進行授權就沒有問題了:
[root@localhost][mysql]> flush privileges; Query OK, 0 rows affected (0.01 sec) [root@localhost][mysql]> grant all privileges on *.* to 'root'@'%'; Query OK, 0 rows affected (0.01 sec)
也可以如下進行授權:
[root@localhost][mysql]> grant all privileges on *.* to 'root'@'%' with grant option; Query OK, 0 rows affected (0.00 sec) [root@localhost][mysql]> [root@localhost][mysql]> flush privileges; Query OK, 0 rows affected (0.01 sec)
然后在客戶端可以訪問了。