Terminalden MySQL'e bağlanmaya çalışırken eğer aşağıdaki hatayı alırsanız, yine aşağıdaki yöntemle problemi çözebilirsiniz.


$ mysql -u root
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

MySQL server konfigürasyon değişikliği


Sisteminizdeki my.cnf dosyasını aşağıdaki gibi değiştirin, kaydedin ve çıkın.


# Assuming that this is where you config file is located
$ sudo nano /etc/mysql/my.cnf

# Update the 'socket' config as follows
[client]
socket = /var/lib/mysql/mysql.sock

[mysqld_safe]
socket = /var/lib/mysql/mysql.sock

[mysqld]
socket = /var/lib/mysql/mysql.sock

MySQL server'i yeniden başlatma


$ sudo service mysql restart
mysql stop/waiting
mysql start/running, process 6372

Hakları değiştirme


Buna gerek kalmayabilir.


$ sudo chmod 777 /var/lib/mysql/mysql.sock
# OR
$ sudo chmod -R 755 /var/lib/mysql/

Test


$ mysql -u root
Welcome to the MySQL monitor.
........
........
mysql>

Alternatif çözüm


Aşağıdaki komutun problemsiz bir şekilde çalışması lazım.


$ mysql -u your_username -pyour_password -h 127.0.0.1