Linux, MySQL forgotten password solution

1. stop the MySQL service
sudo systemctl stop mysql

2. Start with MySQL security command, skip the permissions tables and network
sudo mysqld_safe --skip-grant-tables --skip -networking &

The role of the end of the ampersand is to let the process run in the background, allowing users to continue to enter commands.
After executing this command, you can use #mysql -u root avoid dense logged.

3. If you enter this command returns the following error message
2018-02-12T08: 57: 39 mysqld_safe Directory '/ var / RUN / mysqld' for UNIX
socket do not EXISTS File -u root MySQL ERROR 2002 (HY000):. Of Can 'Connect to local T through the MySQL Server Socket
' /var/run/mysqld/mysqld.sock '(2) [. 1] +. 1 the Exit

# Create a directory MySQL service
sudo mkdir / var / run / mysqld

# Modify the access rights to
sudo chown mysql: / var / run / mysqld

4. Run the second point command

5. Run the command mysql -u root avoid dense login MySQL.
mysql> FLUSH PRIVILEGES;

# For MySQL 5.7.6 and above
mysql> ALTER USER 'root' @ 'localhost' IDENTIFIED BY 'new_password';

# For MySQL 5.7.5 and following versions
mysql> SET PASSWORD FOR 'root' @ 'localhost' = PASSWORD ( 'new_password');

# If the above command is given, run the following command
mysql> UPDATE mysql.user SET authentication_string = PASSWORD ( 'new_password') WHERE User = 'root' AND Host = 'localhost';

6. Stop the security service, terminate the process with the kill command
sudo kill `cat / var / run / mysqld / mysqld.pid`

# If the command error, run the following command
sudo pkill mysql

7. Restart normal MySQL service
sudo systemctl start mysql

 

Guess you like

Origin www.cnblogs.com/maluscalc/p/11094726.html