Friday, 27 May 2016

MySQL - Can't connect To Server [Fix]

I think you didn't started your database server, start it using

#services mysql start
#/etc/init.d/mysql start

If you are getting a failure message while starting, check the log file (/var/log/syslog), if you found socket connection error message there, then

check for correct socket file location #find / -type s, if you found a mysqld.sock file under /var/run/mysqld/ directory, check whether any instances of mysqld running or not 

#netstat -anpt | grep 3306 or #ps aux | grep mysqld 

if you found any running process stop it (#kill -9 pid) and remove the socket file. Then try to restart it and if mysql not creating socket file then try start it like

#/usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql 

--pid-file=/var/run/mysqld/ --socket=/var/run/mysqld/mysqld.sock

 Also check your my.cnf file (/etc/mysql/my.cnf) and comment the bind-address field, and if you found any skip-network field comment it.