Missing /var/lib/mysql/mysql.sock file

2019-04-03 11:31发布

问题:

I'm trying to access mysql and when I run the mysql command, I get the following.

[root@ip-10-229-65-166 tpdatabase-1.8.0.28356]# mysql

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

Doing this returns nothing

[root@ip-10-229-65-166 mysqld]# find -name mysql*

[root@ip-10-229-65-166 mysqld]# /etc/init.d/mysql stop -bash: /etc/init.d/mysql: No such file or directory

[root@ip-10-229-65-173 tpdatabase-1.8.0.28356]# mysql_config |grep -- --socket

--socket [/var/lib/mysql/mysql.sock]

Maybe a permissions problem?

I do have mysql installed using yum install mysql

I'm running CentOS 5.4 on a Amazon EC2 Cloud Instance

回答1:

You need to install the server package:

sudo yum install mysql-server

After installation, you have to start the service:

sudo service mysqld start


回答2:

We faced a similar problem in my office setup with the same OS. The actual thing that was happening was low space on the server. It is quite strange, but i believe if the server gets full the files cannot be loaded or of some other resort. Please check to be sure the space on the server is enough else you have to try removing the installed mysql and reinstall. Best of luck.



回答3:

just search for mysqld, this is the server daemon:

find / | grep mysqld

If you found it, the server package may be correctly installed but without initd scripts. For testing, you may start the mysql server by hand executing the above file.



回答4:

rm -rvf /var/lib/mysql/ib_logfile*
touch /var/lib/mysql/mysql.sock
touch /var/lib/mysql/mysql.pid
chown -R mysql:mysql /var/lib/mysql
systemctl restart mysql

try this and check the permission of both /var/lib/mysql/mysql.sock and /tmp



回答5:

mysql might have been packaged separately as client and server. Check your package repositories to make sure that the server has been installed. The mysql package might only be the client. Check if there's a package called mysql-server or something similar. Check the list of files installed by the mysql package to see if it actually installs the server.

If the files are not even there, it's not a permissions problem. Also, you're running as root.



回答6:

Before hitting mysql on command prompt make sure your correct my.cnf configuration file is in placed and set the permission of etc folder as

chmod -R 777

etc folder as below list to avoid

error MySQL - ERROR 2002 (HY000): e.g /etc/my.cnf, /etc/mysql/my.cnf, $MYSQL_HOME/my.cnf [datadir]/my.cnf ~/.my.cnf