I have a MySQL server running on my work computer, which runs Mac OS X Maverick. I want to access it from home computer, which also has Mac OS Maverick.

From terminal, if in 1 tab, I ssh into my work computer and just let the ssh session sit there without being idle, then on another tab, I can access MySQL server.

However, without the ssh session running, I will get following error

ERROR 2003 (HY000): Can't connect to MySQL server on 'SERVER_IP_ADDRESS' (60)

I've tried to modify my.cnf file on the server by commenting out bind-address or assigning it to 0.0.0.0 but it doesn't work.

Why is it like that? How can I configure the server so that it allows remote access without having to run ssh on the client? Can someone please help?

  • I have the same problem with PostGIS running on remote OS X...can connect to database when ssh is open in one tab, but otherwise not. I think the problem is that the database server process is paused or not running when I am not logged in to the remote server. – andybega Apr 28 '15 at 6:57

I have been banging my head against this error today on OSX Yosemite with MySQL 5.7 recently updated with Homebrew. Following suggestions on StackOverflow and elsewhere, I hunted around after my.cnf files all of which specified bind-address=0.0.0.0. I even removed and reinstalled MySQL following these instructions and then reinstalled using brew install mysql. Still no remote connections allowed.

It wasn't until I ran ps -ax | grep mysql and noticed that the bind address was being passed in the launch command (thus overriding any my.cnf files) that I dug some more and found out that Homebrew binds MySQL to 127.0.0.1 by default.

Editing ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist to change --bind-address=127.0.0.1 to --bind-address=0.0.0.0 solved my problem (the latter should be changed to a specific IP address if this isn't just a development machine).

I feel this is a vital piece of information that was lacking from most of the resources I consulted so hopefully posting this here will help someone else!

EDIT: As LeandroCR indicated in the comments, running brew services restart mysql will overwrite the plist file in LaunchAgents with the default one, leading to MySQL mysteriously refusing connections again. So better advice than what I originally wrote is the following:

  1. Edit /usr/local/Cellar/mysql/<yourversion>/homebrew.mxcl.mysql.plist and replace --bind-address=127.0.0.1 with bind-address=* or --bind-address=0.0.0.0 (see MySQL documentation on bind-address)
  2. Restart mysql using brew services restart mysql

Then MySQL should continue to accept non-local connections from then on - until you reinstall it, presumably.

  • 3
    Another tip: If you are running $ brew services restart mysql it will cleanup the plist file from LaunchAgents every time. If you want to persist that change edit /usr/local/Cellar/mysql/<yourversion>/homebrew.mxcl.mysql.plist - Also Emma thanks a lot!!! – LeandroCR Jul 15 '16 at 2:27
  • I've installed mysql 5.6 using brew install mysql56, and I changed bothe the ~/Library/LaunchAgents/homebrew.mxcl.mysql56.plist and /usr/local/Cellar/mysql56/5.6.32/homebrew.mxcl.mysql56.plist files. But still when I launch mysql through mysql.server start, the ps command shows that the bind-address=127.0.0.1. Is there any other files to edit? – xi.lin Nov 5 '16 at 7:45
  • @xi.lin As I understand it, mysql.server start bypasses the LaunchAgent, so it probably gets its setting from somewhere else. To use the setting in the plist, you probably have to use brew services restart mysql – Emma Burrows Nov 5 '16 at 12:25
  • @EmmaBurrows Using brew services restart mysql output Successfully started mysql` (label: homebrew.mxcl.mysql)` but still the address is 127.0.0.1 . Actually I couldnot find homebrew.mxcl.mysql.plist instead of having homebrew.mxcl.mysql56.plist – xi.lin Nov 7 '16 at 9:29
  • Maybe you have more than one version of MySQL (I think I ended up in that situation once), in which case brew services restart mysql56 might be the thing to do. That's all I can think of! – Emma Burrows Nov 7 '16 at 12:09

I hope you need to create the user for remote access with '%' wildcard and grant permissions on DB's.

Step 1:

In my.cnf (https://serverfault.com/questions/9107/how-do-i-find-where-mysql-is-loading-its-config-from) comment out your bind address

# bind-address        = xxx.xxx.xxx.xxx

And restart MySQL Server.

Step 2:

Then you need to grant permissions to user for remote access

GRANT ALL ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypass';

Please have a look on How to enable remote connection.

  • I've tried this setting (commenting out bind-address) before and it didn't work. I've created a user and granted all permission as well. mysql> show grants for 'home'; | Grants for home@% | GRANT ALL PRIVILEGES ON *.* TO 'home'@'%' IDENTIFIED BY PASSWORD '...' WITH GRANT OPTION | – chepukha Jan 2 '14 at 5:32
  • Do you have any firewall in place ? If it is please disable that. – Abdul Manaf Jan 2 '14 at 5:36
  • Yes, I can access the server when firewall is turned off. But can I configure the firewall to allow remote access to sql server rather than completely turn it off? On the server, in firewall settings, I've set mysqld to "allow incoming connections" – chepukha Jan 2 '14 at 6:00
  • Do you have SQL Server also installed on same machine ? – Abdul Manaf Jan 2 '14 at 6:05
  • Yes, I do. You mean SQL server and Firewall on the same machine? – chepukha Jan 2 '14 at 6:06

Running locate my.cnf found the file /usr/local/etc/my.cnf

  1. Edit that file and set bind-address = 0.0.0.0
  2. Restart mysql: brew services restart mysql

Check iptables as iptables -L

If your IP is not present then add it

In case of Ubuntu ADD IP to allow access :

iptables -A ALLOWIN -s 192.168.1.XX/32 ! -i lo -j ACCEPT

Your Answer

 
discard

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.