Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Database Discussions' started by adoel, Dec 23, 2016.

Tags:
  1. adoel

    adoel Registered

    Joined:
    Dec 23, 2016
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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.
     
  2. MinhAngela

    MinhAngela Registered

    Joined:
    Dec 23, 2016
    Messages:
    3
    Likes Received:
    3
    Trophy Points:
    3
    Location:
    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:

    [root@tenten-VPS]# 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:

    [root@tenten-VPS]# 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:

    [root@tenten-VPS]# 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:

    [root@tenten-VPS ~]# /etc/init.d/mysqld stop
    Shutting down MySQL............................ SUCCESS!


    Then:

    /etc/init.d/mysqld start

    Result:

    [root@tenten-VPS ~]# /etc/init.d/mysqld start
    Starting MySQL.............................. SUCCESS!


    Check the existence of the file: mysql.sock

    [root@tenten-VPS ~]# 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:

    [root@tenten-VPS ~]# /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 :)
     
    cPanelMichael likes this.
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,424
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page