Solved issue: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock

[root@localhost ~]# mysqladmin -u root shutdown
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/lib/mysql/mysql.sock’ exists!

Solved issue: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock

Using following command I checked the mysql directory.
[root@localhost ~]# ll /var/lib/mysql/

I did not found the mysql.sock file there.

[viral-lock message=”Solution is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]

[root@localhost ~]# cd /var/lib/mysql/
Created file in that location.
[root@localhost mysql]# touch mysql.sock
Gave the executabe permission the sock file.
[root@localhost mysql]# chmod +x mysql.sock
Changed the permission to mysql user
[root@localhost mysql]# chown mysql:mysql -R *

[/viral-lock]

After that restarted the machine
[root@localhost mysql]# /etc/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
[root@localhost mysql]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.52 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;

Can't connect to local MySQL server through socket
Can’t connect to local MySQL server through socket

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

4 thoughts on “Solved issue: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock”

Leave a Reply to wpapi Cancel reply

Your email address will not be published.