MySQL not connecting connects by error in socket

2

Good afternoon friends, after correctly installing MySQL 5.7 on my Ubuntu 16.04, when trying to connect to the database, I get an error message saying that it was not possible to connect through the socket.

Execution: mysql -u root -p

And then I get the error:

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

In the /var/run/mysqld/mysqld.sock directory there is no file with extension .sock

I've already uninstalled and installed, tried with version 5.6 and nothing has worked. Any suggestion? Thanks!

    
asked by anonymous 24.07.2016 / 20:28

1 answer

3

As this answer from SOen, , a common problem that causes ERROR 2002 is to install mysql-client instead of mysql-server .

In ubuntu you can install the package mysql-server with:

sudo apt-get install mysql-server

Another possibility is that the mysql service has not been initialized. In recent versions of Ubuntu you can do this with:

sudo start mysql

Finally it is possible that your mysql is not listening on the default address / port combination ( 127.0.0.1:3306 ). In this case you have two options:

  • Edit your settings in the my.cnf
  • Specify the expected address and port at connect time:

    mysql -h [ip/host] -P [porta] -u root -p [database]  
    
  • 24.07.2016 / 20:44