I can not start mysql in the terminal through a socket, i.e. like this:

mysql -u root 

The following error occurs:

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

Through the network everything turns out:

 mysql -h 127.0.0.1 -u root -p 

What can be wrong ?

    1 answer 1

    You need to inform the server and mysql clients that they will communicate exclusively through a socket. To do this, open the my.cnf configuration file and set the path to the socket in the socket directive in two sections: [client] for clients and in [mysqld] for the server (add these if there are no directives)

     [client] ... socket = /var/run/mysqld/mysqld.sock ... [mysqld] ... socket = /var/run/mysqld/mysqld.sock ... 

    After that, restart the server.

     sudo service mysql restart 

    and make sure that the socket file appears in the / var / run / mysqld / folder. I do not advise placing the file in / tmp, since from there it can be regularly removed by cron-cleaning tasks and you will again and again encounter this error (the / var / run directory itself is intended for sockets and pid-files).

    If you plan to work through a socket, you can generally disable network access, even locally. To do this, in the [mysqld] section of the my.cnf configuration file, install the skip-networking directive

     [mysqld] ... skip-networking