Can't connect to local MySQL server through socket

Cleyton Silva

Active Member
Aug 9, 2016
26
2
3
Suzano, Brazil
cPanel Access Level
Website Owner
Hello, I have problems with my cpanel. When I log into MySQL® Databases
An error message appears:

The MySQL server is currently offline.
Error while connecting to MySQL: (XID qpf9ac) Database Connect Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Error while connecting to MySQL: (XID qpf9ac) Database Connect Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at /usr/local/cpanel/Cpanel/Mysql.pm line 173.
 

Jcats

Well-Known Member
PartnerNOC
May 25, 2011
806
156
168
New Jersey
cPanel Access Level
DataCenter Provider
Can you confirm MySQL is online?

In SSH simply type:

Code:
# mysql
Does it bring up mysql prompt:

Code:
mysql>
or throw an error?

Also what does this give you:

Code:
# ll /var/lib/mysql/mysql.sock
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,203
363
Hello,

Check to see if a .my.cnf file exists under the account's home directory (/home/$username/). If so, verify it uses the correct credentials, or try updating the individual account's MySQL password after consulting with the user via:

"WHM Home » SQL Services » Change MySQL User Password"

Thank you.
 

germany

Member
Jul 15, 2016
17
4
3
Berlin, DE
cPanel Access Level
Website Owner
I think you didn't started your database server, start it using

#services mysql start
or
#/etc/init.d/mysql start


If you are getting a failure message while starting, check the log file (/var/log/syslog), if you found socket connection error message there, then
check for correct socket file location #find / -type s, if you found a mysqld.sock file under /var/run/mysqld/ directory, check whether any instances of mysqld running or not #netstat -anpt | grep 3306 or #ps aux | grep mysqld if you found any running process stop it (#kill -9 pid) and remove the socket file. Then try to restart it and if mysql not creating socket file then try start it like

#/usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock

Also check your my.cnf file (/etc/mysql/my.cnf) and comment the bind-address field, and if you found any skip-network field comment it.