3

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

  • 1) check your firewall and make sure it allows traffic inbound on 3306. 2) run (as root) netstat -ntlup | grep 3306 and make note of the 'local Address'. is it 0.0.0.0:3306 or 127.0.x.y:3306 (x and y can be any number < 255). if its 127.0.x.y, follow these instructions to make it listen for external connections (0.0.0.0:3306). howtogeek.com/howto/mysql/switch-mysql-to-listen-on-tcp – Frank Thomas Jan 17 '14 at 3:48
2

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';

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.