Installing MySQL in Docker fails with error message "Can't connect to local MySQL server through socket"

Solution 1:

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.

Solution 2:

I had the same problem, in fact, I juste forgot to run the service after installation ..

Start mysql server :

/etc/init.d/mysql start

Solution 3:

Don't know how do i achieve this, but, i've be able to reach MYSQL by typing

$ mysql -u root -h

mywebsite:
  image: benftwc/pldev-webserver
  volumes:
    - ./mywebsite.fr/:/var/www/
  working_dir: /var/www/
  ports:
    - "8009:8009"
  command: php -S 0.0.0.0:8009
  links:
    - database
database:
  image: library/mysql
  environment:
    MYSQL_ROOT_PASSWORD: root
  ports:
    - "3310:3306

root@422f4d1f454a:/# mysql -u root -h 127.0.0.1 -p3310
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

root@422f4d1f454a:/# mysql -u root -h database -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g...........