一、允許用戶所有IP訪問
更改?mysql
?數(shù)據(jù)庫里的?user
?表里的?host
?項,從localhost"
改成%
即可。有兩種方式可以實現(xiàn)。
第一種:直接修改user
?表
1. mysql -u root -p
2. select host,user from user where user='root';
3. update user set host = '%' where user='root' and host='localhost';
4. select host, user from user where user='root';
第二種:授權(quán)的方式
grant all privileges on *.* to root@'%' identified by '123' with grant option;
flush privileges;
# *.* 表示所有的數(shù)據(jù)庫 ,可以針對某個數(shù)據(jù)進行設(shè)置,如 on 庫名.表名
# grant all privileges on 庫名.表名 to '用戶名'@'IP地址' identified by '密碼' with grant option;
二、限制某個IP或者IP段訪問
建議通過授權(quán)的方式實現(xiàn)。
#單個IP
grant all privileges on *.* to root@'192.168.1.3' identified by '123' with grant option;
flush privileges;
#IP段,使用%代替IP
grant all privileges on *.* to root@'192.168.1.%' identified by '123' with grant option;
or
grant all privileges on *.* to root@'192.168.%.%' identified by '123' with grant option;
flush privileges;
注意:
1、注意授權(quán)后必須FLUSH PRIVILEGES;否則無法立即生效。
2、高版本無法使用grant all privileges on *.* to "root"@"%" identified by "xxxx";
去修改用戶權(quán)限。文章來源:http://www.zghlxwxcb.cn/news/detail-517419.html
如:文章來源地址http://www.zghlxwxcb.cn/news/detail-517419.html
mysql> SELECT @@VERSION;
+-----------+
| @@VERSION |
+-----------+
| 8.0.14 |
+-----------+
# 先創(chuàng)建遠(yuǎn)程用戶,再授權(quán)
create user 'root'@'%' identified by 'password';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
#查看
select User,Host from user;
到了這里,關(guān)于MySQL系列:限制IP訪問,通過授權(quán)的方式實現(xiàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!