Installed mysql-server через apt-get install on ubuntu 16.04. Password for root for some reason did not ask during the installation.

 sudo service mysql stop sudo mysqld --skip-grant-tables --user=root mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 

I'm trying to reset my password, but something is not working. What to do?

  • The error says rather that mysql is not started at all. Check the mysql logs and see if it remains running - Mike
  • When restarting, the end of the error log 2016-04-26T09: 04: 43.020707Z 0 [Note] Server socket created on IP: '127.0.0.1'. 2016-04-26T09: 04: 43.027673Z 0 [Note] Event Scheduler: Loaded 0 events 2016-04-26T09: 04: 43.027904Z 0 [Note] / usr / sbin / mysqld: ready for connections. Version: “5.7.12-0ubuntu1” socket: “/var/run/mysqld/mysqld.sock”: 3306 (Ubuntu) @ 'localhost' (using password: NO) - djkah11

1 answer 1

This error indicates that your MySQL server is not running. See, you are stopping the MySQL server using regular Ubuntu tools.

 sudo service mysql stop 

Following this, you try to start the server bypassing the service command, without specifying either the socket path or the data directory path.

 sudo mysqld --skip-grant-tables --user=root 

This is not a good idea, you will probably forget something or not. If you need to start a MySQL server without a privilege table, it is better to temporarily edit the my.cnf configuration file (in ubuntu it is located on the /etc/mysql/my.cnf path) and add the skip-grant-tables directive

 [mysqld] ... skip-grant-tables 

After that, start the server using regular Ubuntu tools.

 sudo service mysql start 

PS In addition, you will find the debian.cnf file in the / etc / mysql / folder, which contains the debian-sys-maint system user password - it also has superuser rights, in which case you can go out of it and configure the password and the rights of others users, including root.