X mysql 數據庫增加用戶與為用戶授權。 ERROR 1133 (42000): Can't find any matching row in the user table。


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)

 

然后在客戶端可以訪問了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM