MySQL remote access

After MySQL’s been installed you can access it only from localhost (). It’s configured in my.cnf, in [mysqld] section. Here’s how this setting’s looked by default:

1
2
  # only localhost
  bind-address = 

If bind-address is omitted or set to 0.0.0.0 all other clients will be able to access this MySQL server.

1
2
  # all the clients
  bind-address = 0.0.0.0

Specifying a certain IP address you say to MySQL server to listen connections only from this IP.

1
2
  # for example, only  IP
  bind-address = 

As for me, MySQL server isn’t started if I set a specific IP in bind-address option. Maybe that’s because it bans connections from localhost. Okay, in this case, it’s possible to use a firewall to allow access for one or more IP addresses and set bind-address to 0.0.0.0.

So, to connect to your database remotely from any IP address you should allow your MySQL server to listen all the connections by commenting bind-address or setting it to 0.0.0.0. To enable a remote access only for a particular client you should set bind-address to client’s IP or use a firewall. Using a firewall allows you to set access for one IP address or for multiple IP addresses.

Your changes to my.cnf will be applied only after restarting MySQL server. To reboot MySQL server type this command:

1
2
  # on Debian linux, in my case
  /etc/init.d/mysql restart

Or:

1
2
  # Ubuntu
  sudo service mysql restart

Also, if you want to reboot the mysql server you may stop and then start the service:

1
2
3
4
5
  # Stop
  sudo stop mysql
 
  # Start
  sudo start mysql