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

泪湿孤枕 提交于 2019-12-13 13:08:31

问题


I have installed Centos7 update, removed MariaDB and done a fresh install of MySQL - additionally I have removed it and reinstalled it but everytime I connect to mysql -u root -p I get the titled error. Additionally I have looked at other tickets associated with this but still not making progress. If I run service mysqld restart it says "Redirecting to /bin/systemctl restart mysqld.service" and then just hangs. Really not a linux expert so not sure what is causing this?


回答1:


I had the same problem and found out a few things after digging around. MariaDB is a drop-in replacement for mysql. On the new system, mysql is the MariaDB client (although I'm not clear on what that means). I checked to see if the service was running:

service mysqld status

which indicated:

Redirecting to /bin/systemctl status mysqld.service mysqld.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)

In other words, the mysqld service is not running.

Starting the service worked for me:
`systemctl start mariadb.service`

Now all the mysql commands work as expected.

To tie the last knot, enable the service at boot:
`systemctl enable mariadb.service`



回答2:


Check the 'socket=' entry in your /etc/my.cnf within the [mysqld] section:

[mysqld1]
socket = /tmp/mysql.sock1

An alternate method is to provide the '-hhost' & '-Pport' parameters to the 'mysqladmin' or 'mysql' commands, to avoid using the socket.

mysql -u user -hservername -P3006 -p   -Dschema
mysqladmin -u user -p -hhostname -Pport 



回答3:


Removing the dir fixed it - deleted the dir (with rm -rf "dir name") and then unintalled mysql "yum remove mysql mysql-server" then reinstalled "yum install mysql-server" and ran "service mysqld start"

If you have this problem with the start mysql service hanging - check the logs /var/log/mysqld.log as suggested by Jeremiah.



来源:https://stackoverflow.com/questions/26163704/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-lib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!