Error: Can't connect to local MySQL server through socket

Hi, am having a problem with accessing mysql via the terminal, when i enter the password it gives me the error below, how can i fix this?

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Hi @tface,

What command are you using? What happens if you try the following?

$ mysql -u root -p -h localhost

Cheers, Pascal

Hi Pascal, well i was using $ mysql -u root -p
but the command $ mysql -u root -p -h localhost
gives me the same error message

hi @tface

try $ sudo service mysql start && mysql -u root -p -h localhost

What if you force a TCP connection using the following?

$ mysql -u root -p -h

hi, i tried the command and got the following prompt,

start: Job failed to start

hey, i got this, ERROR 2003 (HY000): Can’t connect to MySQL server on ‘’ (111)

Hi @tface,

Are you sure that the mysql service is running? What do the following commands give you?

$ sudo service mysql status

$ sudo ps aux | grep mysql

What operating system are you running and how did you install MySQL?

Cheers, Pascal

1 Like

Confirm that you have a mysql server running, you may be using the default server or xampp among others, whatever the case, start it, search through your file system for mysql.sock file and append a --socket option onto your command, something like: ./mysql -u root -p --socket /pathto/mysql.sock

1 Like

Hi, pascal Am running un Ubuntu 14.04 I installed mysql using the command;

$ sudo apt-get install mysql-server-5.5

Mysql wasn’t actualy running, i had to uninstall it and re-install it to get back it’s functionality. i used the commands below. Am real new with OpenMRS, am still trying to learn the ropes

sudo service mysql stop  #or mysqld
sudo killall -9 mysql
sudo killall -9 mysqld
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo apt-get purge mysql-server-core-5.5
sudo apt-get purge mysql-client-core-5.5