Newbie in databases. I installed MySQL, entered mysql -u root -p into the terminal, then enter the password. An error occurs:

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

Contents of my.cnf file:

 # # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ 

    1 answer 1

    Judging by the error message, your MySQL server is not running, check if the mysqld processes are hanging

     ps uax | grep mysqld 

    If not, try using the command

     sudo service mysql start 

    With the service command, you can control the MySQL server, for example, stop

     sudo service mysql stop 

    or restart

     sudo service mysql restart 

    If an attempt to start the server does not produce results, it does not appear among the processes, you should refer to the logs in / var / log / mysql, maybe there is some additional information reported about why the server cannot start.

    Check where the socket file is located. To do this, open the /etc/mysql/my.cnf configuration file, find the [mysqld] section and the socket directive. It usually points to /var/run/mysqld/mysqld.sock. If your path does not match the one reported by the mysql utility, try to specify it explicitly.

     mysql -u root -p --socket=/var/run/mysqld/mysqld.sock 

    UPDATE

    If the socket is disconnected at all, then the interaction takes place through the network, in this case, the IP address should be 127.0.0.1

     mysql -h 127.0.0.1 -u root -p 

    There are two ways to connect to the MySQL server: through a socket and through the network. When you write localhost as a host - the default connection is through a socket, when you write an IP address - via the network.

    • The mysql file in the logs is empty for some reason ... - faoxis
    • @faoxis mysqld processes do not see? When trying to start some messages are displayed? - cheops
    • In the process there. There are no messages at startup. Restart did - does not help. - faoxis 2:26 pm
    • @faoxis corrected the answer, please see the last paragraph - do you have a socket file in my.cnf exactly /tmp/mysql.sock? And not /var/run/mysqld/mysqld.sock? - cheops
    • I have none at all. There was no my.cnf file in the /etc/ folder. But I found it in /etc/mysql/my.cnf . So, here the socket is not specified at all. I supplemented the question entirely with the contents of the file my.cnf . - faoxis