cPanel User Cant Connect to /usr/lib/mysql/mysql.sock

adoel

Registered
Dec 23, 2016
1
0
1
Indonesia
cPanel Access Level
Root Administrator
Please help me to address this issue.

When my cPanel user open My Databases, got this error:

Code:
The MySQL server is currently offline.

Error while connecting to MySQL:(XID z6tbyn) Database Connect Error: Can't connect to local Mysql server through socket '/var/lib/mysql/mysql.sock' (2) Error while connecting to MySQL: (XID z6tbyn) 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 174
but when user create database through MySQL Database Wizard, it run smoothly. Also user can see that created database on phpmyadmin.

I've tried to restart mysql through WHM and run successfully, but the problem still exists.

Any suggestions would be appreciated.
 

MinhAngela

Registered
Dec 23, 2016
3
3
3
Ho Chi Minh
cPanel Access Level
Website Owner
You can do Step by Step to solve it:

1. Check the existence of mysql.sock file

ls -la /var/lib/mysql/mysql.sock

This is the result you got:

[[email protected]]# ls -la /var/lib/mysql/mysql.sock
ls: cannot access /var/lib/mysql/mysql.sock: No such file or directory


2. Check your setting (in my.cnf ) that changed the root in mysql.sock

netstat -lnp | grep mysql

IF the result is:

[[email protected]]# netstat -lnp | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 25151/mysqld
unix 2 [ ACC ] STREAM LISTENING 27600272 25151/mysqld /var/lib/mysql/mysql.sock


It means that the root to mysql.sock is okay, so mysql.sock has not yet created.

3. Check the working of mysql

ps ax | grep mysql

The result you got:

[[email protected]]# ps ax | grep mysql
16343 ? S 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/tenten.myvps.vn.pid
16653 ? Sl 2:50 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/tenten.myvps.vn.err --open-files-limit=8192 --pid-file=/var/lib/mysql/tenten.myvps.vn.pid
19786 pts/1 S+ 0:00 grep mysql


So, mysql works well.

4. Restart the mysql to re-create mysql.sock

Method 1:

Command:

/etc/init.d/mysqld stop

Result:

[[email protected] ~]# /etc/init.d/mysqld stop
Shutting down MySQL............................ SUCCESS!


Then:

/etc/init.d/mysqld start

Result:

[[email protected] ~]# /etc/init.d/mysqld start
Starting MySQL.............................. SUCCESS!


Check the existence of the file: mysql.sock

[[email protected] ~]# ls -la /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Sep 29 10:32 /var/lib/mysql/mysql.sock


Method 2:

Command:

killall -9 mysqld mysqld_safe
killall -9 mysqld mysqld_safe


Then restart mysql

/etc/init.d/mysqld start

This is the result:

[[email protected] ~]# /etc/init.d/mysqld start
Starting MySQL.............................. SUCCESS!


And finally, check the existence of the file: mysql.sock as above.

I hope this can help you out :)
 
  • Like
Reactions: cPanelMichael

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
Hello,

You may also want to verify 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.