Reputation: 600
I have a problem with my mysql-server in vagrant. Everytime i restart my vagrant box with vagrant reload
or vagrant up
i get this confusing error.
My vagrant box is this one here: ubuntu/trusty64
from
Vagrant-Boxes
This error has been answered already several times here and at askubuntu.
but i want to know why only this code works for me:
su - mysql -s /bin/sh -c "/usr/bin/mysqld_safe > /dev/null 2>&1 &"
the code is from the file mysql*
at /etc/init.d/mysql
.
can anyone explain what the code means?
all this answeres did not help me for explanation from here:
mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Upvotes: 0
Views: 6845
Reputation: 90
this work for me:
sudo service mysql stop
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start
Upvotes: 4
Reputation: 8395
The error means the connection to the server failed, and the root cause is that the MySQL
server is not running, most likely because it was not started.
You need to make sure the machine startup scripts do start MySQL
, in the proper order (the server before clients connections to it), and be sure to wait for the startup to actually complete.
The following script
su - mysql -s /bin/sh -c "/usr/bin/mysqld_safe > /dev/null 2>&1 &"
does start the MySQL server.
What it does is:
su - mysql
)-s /bin/sh
)-c
)/usr/bin/mysqld_safe > /dev/null 2>&1 &
This command:
/usr/bin/mysqld_safe
)> /dev/null
)2>&1
)&
)Upvotes: 2