MySql server only working with localhost

apache-http-serverlocalhostMySQL

I installed mysql server on my machine and I could connect using MySqlWorkbench as localhost (port:3306). But when I change the localhost to my machine name it is not working. I need to access the database from another machine where my webserver resides, so accessing as localhost would not help. What could be wrong?

PS. I could access local apache as localhost:8080 as well as machinename:8080. I was expecting similar behavior with MySql

Best Answer

The computers that are allowed to connect to a mysql server are defined in /etc/my.cnf

You will need to edit the file to allow connection from all computers

[mysqld]
bind-address = localhost #Change from localhost to '0.0.0.0' (all zeros) 
skip-networking   #Comment out this line if it exits
enable-named-pipe #Comment out this line if it exists

Be careful, once you have changed the bind-address from localhost to 0.0.0.0, mysql will allow connections from anywhere. You should lock down your firewall to only allow specific machines in.

You also may need to modify the database to allow remote connections. If your ip of the remote machine is 192.168.1.100

 GRANT ALL PRIVILEGES ON *.* TO db_user @'192.168.1.100' IDENTIFIED BY 'db_passwd';