Mysql adding user for remote access

Follow instructions (steps 1 to 3 aren't needed in Windows):

  1. Find mysql config to edit:

/etc/mysql/my.cnf (Mysql 5.5)

/etc/mysql/conf.d/mysql.cnf (Mysql 5.6+)

  1. Find bind-address=127.0.0.1 in config file change bind-address=0.0.0.0 (you can set bind address to one of your interface IPs or like me use 0.0.0.0)

  2. Restart mysql service run on console: service mysql restart

  3. Create a user with a safe password for remote connection. To do this run following command in mysql (if you are linux user to reach mysql console run mysql and if you set password for root run mysql -p):

GRANT ALL PRIVILEGES ON *.* TO 'remote'@'%' IDENTIFIED BY 'safe_password' WITH GRANT OPTION;

Now you should have a user with name of user and password of safe_password with capability of remote connect.


In order to connect remotely, you have to have MySQL bind port 3306 to your machine's IP address in my.cnf. Then you have to have created the user in both localhost and '%' wildcard and grant permissions on all DB's as such . See below:

my.cnf (my.ini on windows)

#Replace xxx with your IP Address 
bind-address        = xxx.xxx.xxx.xxx

Then:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';

Then:

GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';
FLUSH PRIVILEGES;

Depending on your OS, you may have to open port 3306 to allow remote connections.