I'm trying to install mysql inside a docker container,Tried various images from github, it seems they all manage to successfully install the mysql but when I try to run the mysql it gives an error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
System specifications:
Packages I tried so far:
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.
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.
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.
This Connect to mysql in a docker container from the host may help. mysql command try to connect via mysqld.sock, but your mysql server are running inside a container, so no .sock file here. You can try to mount it to the host.
This error message is basically telling you that the application is not able to locate the socket file needed to establish a MySQL connection. And as you well know the socket file is used by the operating system to enable interface services such as MySQL or PHP to interact and communicate among each other.
To check if MySQL is running, run the following command: And if the service is not running, then, by all means, start it up by running the following command: Once you restart the service, try again to connect to MySQL.
Remember that you will need to connect to running docker container. So you probably want to use tcp instead of unix socket. Check output of docker ps
command and look for running mysql containers. If you find one then use mysql command like this: mysql -h 127.0.0.1 -P <mysql_port>
(you will find port in docker ps
output).
If you can't find any running mysql container in docker ps
output then try docker images
to find mysql image name and try something like this to run it:
docker run -d -p 3306:3306 tutum/mysql
where "tutum/mysql" is image name found in docker images
.
I had the same problem, in fact, I juste forgot to run the service after installation ..
Start mysql server :
/etc/init.d/mysql start
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With