如何授予整个子网的MySQL远程访问权限? [英] How to grant remote access to MySQL for a whole subnet?
问题描述
我可以使用以下代码轻松地授予对一个IP的访问权限:
I can easily grant access to one IP using this code:
$ mysql -u root -p
Enter password:
mysql> use mysql
mysql> GRANT ALL ON *.* to root@'192.168.1.4' IDENTIFIED BY 'your-root-password';
mysql> FLUSH PRIVILEGES;
但是我需要允许整个子网192.168.1.*远程访问数据库.
But i need to allow the whole subnet 192.168.1.* to access the database remotely.
我该怎么做?
推荐答案
Consider looking at and upvoting Malvineous's answer on this page. Netmasks are a much more elegant solution.
只需在IP地址中使用百分号作为通配符即可.
Simply use a percent sign as a wildcard in the IP address.
来自 http://dev.mysql.com/doc/refman /5.1/en/grant.html
您可以在主机名中指定通配符.例如,
user_name@'%.example.com'
适用于user_name
域中任何主机的user_name
,user_name@'192.168.1.%'
适用于192.168.1
C类子网中任何主机的user_name
.
You can specify wildcards in the host name. For example,
user_name@'%.example.com'
applies touser_name
for any host in theexample.com
domain, anduser_name@'192.168.1.%'
applies touser_name
for any host in the192.168.1
class C subnet.
这篇关于如何授予整个子网的MySQL远程访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!