mysql IP限制 iP授權

2021-09-02 12:51:47 字數 1968 閱讀 3379

遠端連線mysql時提示如下:

錯誤碼:1045

access denied for user '[email protected]'(using password:yes)

這個提示通常是由於mysql預設的ip限制原因。

登入mysql後執行

mysql>use mysql;

mysql>select user,host from user;

+------+-----------------------+

| user | host |

+------+-----------------------+

| root | 127.0.0.1 |

| root | ::1 |

| root | localhost |

| root | localhost.localdomain |

+------+-----------------------+

4 rows in set (0.00 sec)

這裡把本機ip授權後即可登入了,具體操作如下:

mysql>grant all on *.* to root@'10.190.0.118' identified by 'mysqlpwd';

query ok, 0 rows affected (0.00 sec)

mysql>flush privileges;

query ok, 0 rows affected (0.00 sec)

mysql>select user,host from user;

+------+-----------------------+

| user | host |

+------+-----------------------+

| root | 127.0.0.1 |

| root | 10.190.0.118 |

| root | ::1 |

| root | localhost |

| root | localhost.localdomain |

+------+-----------------------+

5 rows in set (0.00 sec)

mysql grant語法如下:

grant 許可權名(所有的許可權用all) on 庫名(*全部).表名(*全部) to 要授權的使用者名稱@』ip位址』(可以用%表示所有的ip,也可以指定乙個ip或ip段) identified by 「密碼」;

可以指定許可權,例如:

grant select,insert,update,delete on dbname.* to 'test_user'@'10.190.0.118' identified by 'mysqlpwd'

收回許可權,可以使用revoke,語法基本差不多,例如:

revoke select,insert,update,delete on dbname.* to 'test_user'@'10.190.0.118' identified by 'mysqlpwd'

最後記得操作完成要重新整理許可權,才能生效:

mysql>flush privileges;

query ok, 0 rows affected (0.00 sec)

mysql>quit;

bye

Mysql建立使用者與授權,限制IP

1.建立使用者 create user dog localhost identified by 123456 create user 使用者名稱 限制的ip位址 identified by 密碼 2.授權 grant select,insert on test.user to pig grant a...

簡單IP限制

limitip file iplist.txt 單個ip限制 cip server remote addr 分解客戶端ip cips explode cip ip area1 cips 0 cips 1 cips 2 ip area2 cips 0 cips 1 ip area3 cips 0 rs...

限制ip操作

二 多個ip段限制 region 檢測客戶端ip是否在某一ip段內 客戶端ip 1,通過 0 不通過 public int ipexamination string clientip intksip iptoint ksip intjsip iptoint jsip intclientip ipto...