0

I get an error on my website (MySQL with TCP/IP connection)

Can't connect to local MySQL server

It sounds easy, perhaps, but not so easy to solve as would seem. At first i verified that mysqld process is running. Then connected to SSH server and started /etc/init.d/mysqld restart, but nothing has changed. Also i checked is the server running, using telnet your-host-name tcp-ip-port-number, just in case, but MySQL does not work on this port and shows another error: telnet: Unable to connect to remote host: Connection refused The last i have tried is to run mysql with the skip-networking option, and it did not help as well as other attempts above. Any suggestions would be very appreciated.

Baerbald
  • 3
  • 1
  • Can you describe the architecture of the system? Is your mysqld instance on the same server as your webserver? What are your mysqld configuration strings in your server/software? – Reenactor Rob Mar 11 '15 at 13:24

4 Answers4

1

This error normally means that MySQL is not running on the system or that you are using a wrong TCP/IP port number while trying to connect to the mysqld server.

Try to connect to the mysqld daemon on the local machine and check by mysqladmin variables, which TCP/IP port is configured to use mysqld (variable port).

Perhaps you are running MySQL-server with no corresponding privileges for the directory holding the socket file. In this case, either change the privilege for the directory or restart mysqld

Also this discussion might be interesting for you: http://community.office365.com/en-us/f/172/p/266451/815406.aspx

Unfortunately, i am not a pro and my advices can help not much, but that all what i found about your issue

Bertrannus
  • 26
  • 1
0

This sounds like you are being blocked by the firewall on the server. You can disable the firewall for a quick test:

service iptables stop
service iptables start

This article will show you how to apply rules to the firewall to allow mysql access.

http://www.cyberciti.biz/tips/linux-iptables-18-allow-mysql-server-incoming-request.html

If you have SELinux, you have another set of problems which I can't help you with.

Community
  • 1
  • 1
Reenactor Rob
  • 1,508
  • 1
  • 11
  • 20
0

Sounds to me permission issue.

Does it run on the local machine? If yes, then it might me possible it isn't allowed to listen any port(security purposes: mostly on a linux based server). Otherwise, Network user might not have permission granted to access mysql over internet.

As you say, if it's a website, I would never allow user access mysql directly but only the server shall: possible security breach otherwise.(you don't want your database to be dropped, do you?)

Well still, proper answer to you question resides here: http://dev.mysql.com/doc/refman/5.1/en/grant.html

and this might help: Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server

Community
  • 1
  • 1
Sal
  • 13
  • 3
0

Firstly, you should verify that MySQL is actually running by checking your processlist. On linux you could do that like this, note that you should see both mysqld_safe and then mysqld as two separate processes.

sudo ps auxwww|grep -i mysqld

If it is not running, I would check the MySQL error log for clues as to why it is not starting.

If you then verify that it is running, we can check to see what ports or unix sockets it is listening on like so. If this doesn't work, get the process ID of mysqld (not mysqld_safe) and try search for that with grep instead of 'mysql'

sudo netstat -anp|grep -i mysql

You'll obviously want to restart without skip-networking to see a TCP socket appear.

Based on the output of that, you should see both a unix socket and a tcp socket. Also check the address in the fourth column for the TCP socket, it will likely say either 127.0.0.1:3306 or 0.0.0.0:3306. The former means that you can only connect via localhost (127.0.0.1) and the latter means the connection will work on any IP address.

If you've gone through all of that and are still not sure why it is working, you could post the processlist and netstat outputs for further review, along with the exact settings you are using to try and connect to MySQL and indicate whether you are connecting from the same server (i.e. locally) or from another server over the network.

See also: http://dev.mysql.com/doc/refman/5.6/en/can-not-connect-to-server.html

Trent Lloyd
  • 1,832
  • 1
  • 15
  • 13