Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
Question
I am having a big problem trying to connect to mysql. When I run:
/usr/local/mysql/bin/mysql start
I have the following error :
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
I do have mysql.sock
under the /var/mysql
directory.
In /etc/my.cnf
I have:
[client]
port=3306
socket=/var/mysql/mysql.sock
[mysqld]
port=3306
socket=/var/mysql/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
and in /etc/php.ini
I have :
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /var/mysql/mysql.sock
I have restarted apache using sudo /opt/local/apache2/bin/apachectl restart
But I still have the error.
Otherwise, I don't know if that's relevant but when I do mysql_config --sockets
I get
--socket [/tmp/mysql.sock]
Accepted Answer
If your file my.cnf (usually in the /etc/mysql/ folder) is correctly configured with
socket=/var/lib/mysql/mysql.sock
you can check if mysql is running with the following command:
mysqladmin -u root -p status
try changing your permission to mysql folder. If you are working locally, you can try:
sudo chmod -R 755 /var/lib/mysql/
that solved it for me
Read more… Read less…
are you sure you installed mysql as well as mysql server..
For example to install mySql server I'll use yum or apt to install both mysql command line tool and the server:
yum -y install mysql mysql-server (or apt-get install mysql mysql-server)
Enable the MySQL service:
/sbin/chkconfig mysqld on
Start the MySQL server:
/sbin/service mysqld start
afterwards set the MySQL root password:
mysqladmin -u root password 'new-password' (with the quotes)
I hope it helps.
A quick workaround that worked for me: try using the local ip address (127.0.0.1) instead of 'localhost' in mysql_connect(). This "forces" php to connect through TCP/IP instead of a unix socket.
I got the following error
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
Tried several ways and finally solved it through the following way
sudo gksu gedit /etc/mysql/my.cnf
modified
#bind-address = 127.0.0.1
to
bind-address = localhost
and restarted
sudo /etc/init.d/mysql restart
it worked
To prevent the problem from occurring, you must perform a graceful shutdown of the server from the command line rather than powering off the server.
shutdown -h now
This will stop the running services before powering down the machine.
Based on Centos, an additional method for getting it back up again when you run into this problem is to move mysql.sock:
mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
service mysqld start
Restarting the service creates a new entry called mqsql.sock