1

I have mariadb installed and running.

I can connect to it with this:

mysql -u dev -p

or

mysql -h localhost -u dev -p

but I can't connect to it using

mysql -h 127.0.0.1 -u dev -p

It asks me for my pwd, which I enter. but after that it just hangs.

I need to be able to connect with 127.0.0.1 because I am using jdbc and I want to make connection using that.

Anthony
  • 253
  • 1
  • 7
  • 10

1 Answers1

3

MySQL will sometimes treat 'localhost' as a reference to the local socket i.e: /var/run/mysqld/mysqld.sock instead of the network address 127.0.0.1

First, you should edit the MySQL config file my.cnf

Change the following line:

socket = /var/run/mysqld/mysqld.sock

To:

bind-address = 127.0.0.1

And restart mysqld, service mysqld restart

If you are still having problems, make sure to check your firewall rules to see if there is anything preventing access to/from 127.0.0.1:3306

David Houde
  • 3,200
  • 1
  • 16
  • 19
  • I don't have `/var/run/mysqld/mysqld.sock` file. When I turn off iptables then I can make the connection to 127.0.0.1 so I think it has to do with iptables. But even when I open port 3306 I can't connect. This is a AWS box. – Anthony Nov 02 '13 at 13:37