Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my Ubuntu's /etc/mysql/my.conf, I have:

bind-address =  # My external IP

It works fine from remote, but when I want to connect locally, the app that uses on MySQL says: Connection refused at com.mysql.jdbc.StandardSocketFactory.connect.

So when I want to work locally, I change my.cnf to:

bind-address =

And it starts working locally, but then it doesn't work from remote anymore.

How to make MySQL accesible both from remote AND local?

share|improve this question
possible duplicate of MySQL: Bind to more than one IP address? – EEAA Aug 18 '10 at 2:06
up vote 9 down vote accepted

Just comment out bind-address= altogether. When you do that, it will bind to all addresses. Also make sure that you don't have skip-networking enabled in your my.cnf.

share|improve this answer
Great, it works! Thanks a lot :-) – Nicolas Raoul Aug 18 '10 at 2:19
Awesome. Glad I could help! – EEAA Aug 18 '10 at 2:21
I have bind-address commented, no skip-networking, my user is defined as 'test3@%', I can connect with mysql -h -P 3306 -u test3 -D test3 and yet I can't connect with localhost. – Adrien Jul 14 '15 at 9:41
@Adrien You need to create another user with the same name that can access to localhost – jedi Jun 26 at 12:54

I've JUST got it to work using the command line tools on the server and remotely via php. Along with making sure skip-networking was hashed out (and our firewall rubbish), what I had to do was:

  1. Try the command line tool on the server hosting the db (e.g. shell> mysql -h localhost -u root -p then enter password)

  2. Make a note of the / path it tries to connect from (ending with .sock)

  3. Go into my.cnf and make sure in the [client] and [mysqld] sections that socket= contains the path you found in step 2.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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