skystar7 skystar7 - 6 months ago 65
SQL Question

How to grant remote access to MySQL for a whole subnet?

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;


But i need to allow the whole subnet 192.168.1.* to access the database remotely.

How can i do that?

Answer

Simply use a percent sign as a wildcard in the IP address.

From http://dev.mysql.com/doc/refman/5.1/en/grant.html

You can specify wildcards in the host name. For example, user_name@'%.example.com' applies to user_name for any host in the example.com domain, and user_name@'192.168.1.%' applies to user_name for any host in the 192.168.1 class C subnet.