I‘m getting the following error when I run mysql -u root -p


Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

How do I solve this problem under CentOS / RHEL / Red Hat Enterprise Linux server 5.x or 6.x?

To solve this problem take the following steps.

Is MySQL Running?

Type the following command
# service mysqld status
If mysqld is not running, start it:
# service mysqld start
Try mysql command again as follows:
$ mysql -u USER -p

Is MySQL Installed?

Make sure the package mysql-server is installed:
# rpm -qa mysql-server
Sample outputs:


If you do not see package name, type the following command to install mysql-server:
# yum install mysql-server
Turn on mysqld to start automatically on boot:
# chkconfig mysqld on
Run mysqld service, enter:
# service mysqld start
Set a new root password for mysql server:
# mysqladmin -u root password 'MySQL-Root-User-Password'

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

13 comments… add one
  • CAM Jan 6, 2014 @ 1:05

    What if mysql server is not running? You always get that it needs the mysql.sock to start. Mysql.sock is missing.
    Can this be fixed? and how?

  • Vishwanath Kamble Feb 3, 2014 @ 11:26

    I had this same problem, and I solved it.
    I had entered bind address in my.cnf file and when I started my server today, it took some other IP from DHCP. So just enter the new IP in bind address or just keep

  • nivedita May 10, 2014 @ 11:43

    when we type service mysqld status then unrecognize service error msg show

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.