MySQL forgot root password recovery method

Source: Internet
Author: User

(1) Log on to the server where the database is located, manually kill the MySQL process:

Kill ' Cat/mysql-data-directory/hostname.pid '
among them,/mysql-data-directory/hostname.pid refers to the. pid file in the MySQL data directory, which records the process number of the MySQL service. (2) Restart the MySQL service with the--skip-grant-tables option:
[[email protected] mysql]#/bin/mysqld_safe--skip-grant-tables--user=root &[1] 17299[[email protected] mysql]# 151006 13:14:41 mysqld_safe Logging to '/alidata/log/mysql/error.log '. 151006 13:14:41 mysqld_safe Starting mysqld Daemon with Databases From/alidata/server/mysql/data
whichThe--skip-grant-tables option means to skip the permission table authentication when starting the MySQL service. After startup, the root of the connection to MySQL will not require a command. (3) The root user of the empty password is connected to the MYSQ and the root password is updated:
[[email protected] ~]# mysql-urootwelcome to the MySQL monitor. Commands End With; or \g.your MySQL connection ID is 4Server version:5.5.37-log mysql Community Server (GPL) Copyright (c) #, Oracl e and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement. mysql> Set Password = password (' ysj123 '); ERROR 1290 (HY000): The MySQL server is running with the--skip-grant-tables option so it cannot execute this Statementmys ql> Update Mysql.user Set Password=password (' 123456 ') where user= ' root ' and host= ' localhost '; Query OK, 1 row Affected (0.00 sec) Rows matched:1 changed:1 warnings:0 
at this point, because the--skip-grant-tables option was used to start, changing the password using the "Set Password" command failed to change the password successfully after updating the password field of the user table directly. (4) Refresh the permissions table, so that the Authority certification re-entry into force:
mysql> flush Privileges; Query OK, 0 rows Affected (0.00 sec)
(5) when you re-login with root, you must enter a new password:
[[email protected] ~]# Mysql-urooterror 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using password:no) [[EMA Il protected] ~]# mysql-uroot-penter password:welcome to the MySQL monitor. Commands End With; or \g.your MySQL connection ID is 8Server version:5.5.37-log mysql Community Server (GPL) Copyright (c) #, Oracl e and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Note : In MySQL, the password cannot be retrieved after it is lost, only the password can be changed in the above way. do not forget to give a praise Oh! ~

MySQL forgot root password recovery method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.