Mysql not connecting connects by socket error

Asked

Viewed 5,400 times

2

Good afternoon friends, after having correctly installed Mysql 5.7 on my Ubuntu 16.04, while trying to connect to the bank, I get an error message saying that I could not connect through the socket.

Executed: mysql -u root -p

And right away I get the bug:

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

In the directory /var/run/mysqld/mysqld.sock the file with extension does not exist .sock

I have uninstalled and installed, tried with version 5.6 and nothing has worked. Any suggestions? Thank you!

  • In my.cnf you can edit the . Sock option, unless mistaken. After that use the chmod -R 755 in the directory, example: chmod -R 755 /var/run/mysqld/mysqld.sock.

2 answers

3


In accordance with that reply from Soen, a common problem that causes the ERROR 2002 is to install the mysql-client instead of mysql-server.

In Ubuntu you can install the package mysql-server with:

sudo apt-get install mysql-server

Another possibility is that the mysql service has not been initialized. In recent versions of Ubuntu you can do this with:

sudo start mysql

It’s finally possible that your mysql not listening in the default address/port combination (127.0.0.1:3306). In that case you have two options:

  1. Edit your settings in the archive my.cnf
  2. Specify the expected address and port when connecting:

    mysql -h [ip/host] -P [porta] -u root -p [database]  
    

-2

Hello! I had a problem like this

"ERROR 2002 (HY000): Can’t connect to local Mysql server through socket '/var/run/mysqld/mysqld.Sock' (2)"

then I commented the line sock=/var/run/mysqld/mysqld.sock in /etc/asterisk/cdr_mysql.conf and resolved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.