问题
I trying to install mysql server on ubuntu 16.04, but when I tried to execute the command: sudo mysql_secure_installation. I am getting the error message:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2).
Just tried:
sudo apt install mysql-server mysql-client
This is my sql version installed: (mysql --version
):
mysql Ver 14.14 Distrib 5.7.12, for Linux (x86_64) using EditLine wrapper
It looks like the mysql was installed on my machine.
The fist time I installed mysql server, the installer ask me for the user root password, but the second time, the installer don't ask me for this credentials, and then if I put the command: mysql_secure_installation
, I am getting the same issue:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2).
Also I tried to install alone the mysql server without the client, and the issue is the same. I tried to remove.purge
and reinstall mysql, but I wasn't able to get working mysql, I don't know what is happening.
回答1:
Remove the socket locked file :
sudo rm /var/run/mysqld/mysqld.sock
And start mysql service :
sudo service mysqld start
回答2:
It looks like mysql service is not running on your linux machine. You can check the whether the service is running or not using systemctl
systemctl status mysql
If the service is not running you can start the service using systemctl
sudo systemctl start mysql
But this will start the service for the current session only. If you reboot the machine you have to again start the mysql
server. To auto start the service on reboot execute
sudo systemctl enable mysql
来源:https://stackoverflow.com/questions/38537781/issue-installing-mysql-server-on-ubuntu-16-04