How to open remote access to MySQL

To enable mySQL remote connection we need to follow these steps:

Step1 edit /etc/mysql/my.cnf and change bind-address to:

bind-address        = 0.0.0.0

Step2 log in to mysql (#mysql -u user -p)

CREATE USER 'myUser'@'myRemoteIP' IDENTIFIED BY 'mypassword';

Step3 And then grant that user to whichever DB or table:

GRANT ALL ON myDB.* TO 'myUser'@'myRemoteIP';

The following grants access to asteriskcdrdb database to user mehrdust with the specified IP:

GRANT USAGE ON asteriskcdrdb.* TO 'mehrdust'@'192.168.1.55';

Some more examples where we can use % wildcard to refer to any host/IP :

CREATE USER 'cdr'@'%' IDENTIFIED BY 'PASSWORD';
GRANT SELECT ON asteriskcdrdb.* TO 'cdr'@'%';
FLUSH PRIVILEGES;
GRANT USAGE ON *.* TO 'user'@'%';

grants limitted access to asteriskcdrdb database to user mehrdust with the specified IP

You may also like