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

skystar7 picture skystar7 · Jul 31, 2012 · Viewed 163.4k times · Source

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

Malvineous picture Malvineous · Jul 15, 2016

It looks like you can also use a netmask, e.g.

GRANT ... TO 'user'@'192.168.0.0/255.255.255.0' IDENTIFIED BY ...