3

I got this error on my php script with db:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

and on phpmyadmin:

#2002 Cannot log in to the MySQL server

What is the problem, how can i fix this? I have installed lamp-server..

6 Answers6

3

It seems that the mysql server is not running.

In a normal mysql installation, you can check if the server is running with the following command: service mysql status

For starting it, just run service mysql start.

  • It is running, i checked. Any other solution ? Can i reinstall only mysql, but i have installed lamp server, so it work make any difference to other modules ? And please give me commands to reinstall mysql – Mirza Delic Dec 28 '11 at 17:49
  • Could you check what happens after restarting the server? (service mysql restart) – José Fernández Ramos Dec 28 '11 at 18:11
  • I checked that, but i fixed this with uninstaling mysql-server and mysql-common, then i installed mysql-server and phpmyadmin, and it works, now..

    Thanks.

    – Mirza Delic Dec 28 '11 at 22:18
  • 1
    Kubuntu 13.04 mysql: unrecognized service – Green Jul 20 '13 at 20:52
  • 1
    Ok, just for information, I had to use sudo mysql start in order to make it work. This answer seems to solve the problem. Thank you very much. :) – Geppettvs D'Constanzo Oct 10 '13 at 19:06
2

In my case, I didn't even have the file, so any mysql command wouldn't work. I had to run mysqld_safe to create a new mysqld.sock file. That is:

$ cd /etc/init.d/
$ mysqld_safe

You'll probably won't get prompt back, but if you restart your session, a mysqld.sock file will be somewhere. Find it with

$ sudo find / -type s | grep mysqld.sock
aviggiano
  • 133
  • 4
0

'/var/run/mysqld/mysqld.sock' is created on SQL service startup and deleted on stop.

Its a temp file.

Its missing because SQL has an issue starting.

Most common reason: Your drive is full.

0

Under Ubuntu 14.04 this is running but the socket is not nor the file present. Replace your database connection host to = 127.0.0.1.

tibc-dev
  • 101
0

In my case a local Debian 8 server had shut down while I was away on holiday and by the time I got it restarted it had picked up another IP address from the DHCP server.

I needed to obtain the new IP address like this:

sudo ifconfig eth0 | grep 'inet addr' | cut -d':' -f2 | cut -d' ' -f1

Then I needed to edit my my.cnf file:

vim /etc/mysql/my.cnf

Find this section:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 192.168.0.42

and change it to match the correct IP address:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 192.168.0.53

After that I had no problem getting the server restarted.

  • Mysql defaults to a socket connection when the hostname is localhost, and thus is not applicable. – vidarlo Sep 17 '17 at 16:58
0

i had mysql : mysql --version mysql Ver 15.1 Distrib 10.0.31-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

i have done : sudo apt-get install mariadb-server-10.0

results : no loss of databases and problem resolved :)