Well, it’s probably a question of system permissions or you have only mysql-client installed, but not the mysql-server
and therefore cannot create a UNIX-like Socket file.
So what you should try first is to install mysql-server:
$ sudo apt-get install mysql-server
If you’re sure that the mysql-server
is installed, check the main configuration file, which in Debian and Ubuntu should be on /etc/mysql/my.cnf
or /etc/my.cnf
. My Debian 7 is located at /etc/mysql/my.cnf
.
Your first part of the file should look like this:
Notice that under [client] there is a key called socket
? Well, this is the Unix socket file that mysql uses for local connection by default (unless you don’t force for TCP).
If this file does not exist create it:
$ sudo touch /var/run/mysqld/mysqld.sock
If it exists, try giving the appropriate permissions and paying attention to the group of users:
$ sudo chown -R mysql:mysql /var/lib/mysql
As a final note, you could also connect using TCP instead of UNIX socket.
Some ideas http://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run
– DaviAragao
The first command did not work here. used sudo apt-get remove --purge mysql*
– user3059369
If you are using localhost try using 127.0.0.1
– acacio.martins