Mysql installation socket error

Asked

Viewed 64,762 times

5

I am unable to uninstall or make Mysql 5.5 work on my Ubuntu Linux 14.04.LTS, every time I try to access it, I get the following message:

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

I’ve tried to initiate through command: /etc/init.d/mysql start, but the problem persists. What I’m doing wrong?

  • Some ideas http://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run

  • 1

    The first command did not work here. used sudo apt-get remove --purge mysql*

  • If you are using localhost try using 127.0.0.1

4 answers

8


I am facing the same problem installing version 5.6 of Mysql on Ubuntu 16.04 LTS. After searching and talking with friends, I figured out how to install without error.

First, back up the databases and follow these commands:

$ sudo apt-get remove --purge *mysql/*
$ sudo apt-get autoremove
$ sudo apt-get autoclean
$ sudo rm -rf /var/lib/mysql
$ sudo apt install mysql-server-5.6
$ sudo apt install mysql-client-5.6
  • The first command I think is sudo apt-get remove --purge mysql*

4

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:

inserir a descrição da imagem aqui

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.

  • Thank you for your help, but I had already solved.

  • It worked for me, Server version: 5.7.23-0ubuntu0.16.04.1 (Ubuntu)

1

Well, I think I found the problem, and it was in a very simple way, as I found the problem, it might help others, so I decided to publish the answer:

First I tried to remove the corrupted version: sudo apt-get remove mysql --purge. Then instead of installing "mysql-server-5.5", I just typed in: sudo apt-get install mysql-server. And finally, instead of start, what I needed was restart to set the mysql initializer:
sudo /etc/init.d/mysql restart

After that, I still needed to restart the Mysql service by the command:
sudo service mysql restart

And then it all worked out again...

0

Seems to me to be a PATH friction error.

I had been facing this same error using LAMPP and the command line, but when I used the Phpmyadmin interface, Mysql worked normally.

The solution for me was to copy the LAMPP configuration file(conf. file) to the file contained in etc/mysql/my.cnf and now the command line accesses mysql normally.

Anyway this is just a lame solution

Browser other questions tagged

You are not signed in. Login or sign up in order to post.