Cant connect to local mysql server through socket /var/run/mysqld/mysqld.sock (2) docker

Question

I currenty have a LAMP, running on Ubuntu 14.04, yesterday everything was fine, but today my MYSQL is not working.

When i try to connect via

mysql -u root -p

I get the error: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

the Mysql.err file is completely empty, and have absolute no ideia about what to do.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

0

Docker mysql: ERROR 2002 (HY000): no se puede conectar al servidor MySQL local a través del socket '/var/run/mysqld/mysqld.sock' (2)

Estoy tratando de conectarme al servidor mysql usando mysql cli. La imagen fue creada usando el siguiente comando:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=****** -d mysql

El contenedor acoplable se está ejecutando . docker ps imprime:

johnd@john-pc:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 598c0f8680dc mysql "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 3306/tcp, 33060/tcp some-mysql

Cuando ingreso el siguiente comando: mysql -h 127.0.0.1 -P 3306 -u root -p devuelve:

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

También probé con el atributo --protocol=tcp . ¿Cómo me conecto desde el cliente al servidor mysql que se ejecuta en la ventana acoplable usando la terminal de la máquina cliente (no desde otra ventana acoplable)?

EDITAR: También intenté conectarme a mysql usando este comando:

docker run -it --rm mysql mysql -h227.0.0.1 -uexample-user -p

me devuelve el mismo error

4 months ago ·

Santiago Trujillo

0

mysql -h 127.0.0.1 -P 3306 -u raíz -p

Se está conectando al servidor sql de su localhost pero no asignó el puerto del contenedor de la ventana acoplable al host. Intente mapear el puerto a su host con esto:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=****** -d -p 3306:3306 mysql

Luego vuelve a intentarlo:

mysql -h 127.0.0.1 -P 3306 -u raíz -p

4 months ago · Santiago Trujillo Report

0

el mismo error para mí, solo recuerde iniciar el servicio mysql primero en su contenedor.

exec en su contenedor

/etc/init.d/mysql start

4 months ago · Santiago Trujillo Report

0

El uso de la IP interna de la ventana acoplable como 127.0.0.1 no funcionó para mí

Usé la IP de mi POD y funcionó

mysql -h 10.10.10.41 -P 3306 -u root -p

Todavía no entiendo por qué no pude iniciar sesión y antes y después de este comando pude iniciar sesión

4 months ago · Santiago Trujillo Report

If you happen to get “Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)” errors in logging in to mysql-server while working on docker containers:

check the path of socket file in /etc/mysql/my.cnf

check if mysqld.sock and mysqld.pid file is present in /var/run/mysqld/ directory or not.

If not, create these files as:

touch /var/run/mysqld/mysqld.sock touch /var/run/mysqld/mysqld.pid chown -R mysql:mysql /var/run/mysqld/mysqld.sock chown -R mysql:mysql /var/run/mysqld/mysqld.sock chmod -R 644 /var/run/mysqld/mysqld.sock

Now restart the mysql-server as:

service mysql-server restart

Now, trying logging again in to mysql-server.

My problem started off with me not being able to log in as root any more on my mysql install. I was attempting to run mysql without passwords turned on... but whenever I ran the command

# mysqld_safe --skip-grant-tables &

I would never get the prompt back. I was trying to follow these instructions to recover the password.

The screen just looks like this:

root@jj-SFF-PC:/usr/bin# mysqld_safe --skip-grant-tables 120816 11:40:53 mysqld_safe Logging to syslog. 120816 11:40:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

and I don't get a prompt to start typing the SQL commands to reset the password.

When I kill it by pressing CTRL + C, I get the following message:

error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

If I retry the command and leave it long enough, I do get the following series of messages:

root@jj-SFF-PC:/run/mysqld# 120816 13:15:02 mysqld_safe Logging to syslog. 120816 13:15:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 120816 13:16:42 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended [1]+ Done mysqld_safe --skip-grant-tables root@jj-SFF-PC:/run/mysqld#

But then if I try to log in as root by doing:

# mysql -u root

I get the following error message:

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

I checked and /var/run/mysqld/mysqld.sock file doesn't not exist. The folder does, but not the file.

Also, I don't know if this helps or not, but I ran find / -name mysqld and it came up with:

/var/run/mysqld - folder /usr/sbin/mysqld - file /run/mysqld - folder

I'm new to Linux and MySQL, so I don't know if this is normal or not. But I'm including this info just in case it helps.

I finally decided to uninstall and reinstall mysql.

apt-get remove mysql-server apt-get remove mysql-client apt-get remove mysql-common apt-get remove phpmyadmin

After reinstalling all packages again in the same order as above, during the phpmyadmin install, I got the same error:

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

So I tried again to uninstall/reinstall. This time, after I uninstalled the packages, I also manually renamed all mysql files and directories to mysql.bad in their respective locations.

/var/lib/mysql /var/lib/mysql/mysql /var/log/mysql /usr/lib/perl5/DBD/mysql /usr/lib/perl5/auto/DBD/mysql /usr/lib/mysql /usr/bin/mysql /usr/share/mysql /usr/share/dbconfig-common/internal/mysql /etc/init.d/mysql /etc/apparmor.d/abstractions/mysql /etc/mysql

Then I tried to reinstall mysql-server and mysql-client again. But I've noticed that it doesn't prompt me for a password. Isn't it supposed to ask for an admin password?

Can't connect to local MySQL server through socket error?

It means either the MySQL server is not installed/running, or the file mysql. sock doesn't exist in /var/lib/mysql/ . There are a couple of solutions for this error. Then try to connect again.

Can't connect to local MySQL server on localhost?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

Can't connect to local MySQL server through socket Ubuntu?

To fix the MySQL socket issue and access denied error for root@localhost , follow the below steps. Stop the MySQL server by executing the command “ sudo service mysql stop “. Create socket location as a placeholder by executing the command “ sudo mkdir -p /var/run/mysqld “.

Can't connect to local MySQL server through socket Centos?

You could try using "127.0. 0.1" if the socket connector is not enabled/working. In that case, you should probably check if your MYSQL server is actually running. You can also force using a socket with the socket parameter (-S with /usr/bin/mysql) and force TCP/IP by providing a port (-P with /usr/bin/mysql.)