MySQL forgot root password

Source: Internet
Author: User

MySQL forgot the super user admin password, can take advantage of restarting the MySQL process with the--skip-grant-tables parameter to start the database, and a blank password login. This is the equivalent of the first time the database was started. You can then view the super users in the Mysql.user table and modify the Superuser's password

# close MySQL instance, or kill the process

* Restart MySQL with--skip-grant-tables statement

[[email protected] my.cnf.d]$ mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘  

3# Empty password login MySQL

[[email protected] my.cnf.d]$ msyql -S /data/mysqldata/3306/mysql.sock bash: msyql: command not found...[[email protected] my.cnf.d]$ mysql -S /data/mysqldata/3306/mysql.sock Welcome to the MySQL monitor.  

4# Modifying the Mysql.user table

([email protected])[(none)]> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed([email protected])[mysql]> ([email protected])[mysql]> select user,host,password from user;+------+-----------+-------------------------------------------+| user | host      | password                                  |+------+-----------+-------------------------------------------+| root | localhost | *A0F874BC7F54EE086FCE60A37CE7887D8B31086B |+------+-----------+-------------------------------------------+1 row in set (0.00 sec)([email protected])[mysql]> update user set password=password(‘password123‘) where user=‘root‘;Query OK, 0 rows affected (0.00 sec)Rows matched: 1  Changed: 0  

AA Normal Shutdown database

[[email protected] my.cnf.d]$ mysqladmin -S /data/mysqldata/3306/mysql.sock -uroot -p‘password123‘ shutdownWarning: Using a password on the command line interface can be insecure.180828 19:04:54 mysqld_safe mysqld from pid file /data/mysqldata/3306/mysql.pid ended[1]+  Done                    

6# Normal Open Database

[[email protected] my.cnf.d]$ mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘  &[1] 33094[[email protected] my.cnf.d]$ 180828 19:05:04 mysqld_safe Logging to ‘/data/mysqldata/3306/data/../mysql-error.log‘.180828 19:05:04 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data[[email protected] my.cnf.d]$

7# Normal Login Database

[[email protected] my.cnf.d]$ mysql -uroot -S ‘/data/mysqldata/3306/mysql.sock‘ -p‘password123‘Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  

The root password of MySQL has been modified to complete

MySQL forgot root password

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.