How to reset the password for the MySQL database root user

Source: Internet
Author: User
Tags flush mysql reset safe mode mysql database

First, in a known MySQL database root user password, the method of modifying the password:

1, in the shell environment, using the Mysqladmin command set: mysqladmin–u root–p password "New password" Enter the old password required

2, in the mysql> environment, using the Update command, directly update the MySQL library user table data:

Update Mysql.user Set Password=password (' New password ') where user= ' root ';

Flush privileges;

Note: The MySQL statement ends with a semicolon ";"

3, in the mysql> environment, use the grant command to modify the root user's authorization permissions.

Grant all on *.* to root@ ' localhost ' identified by ' new password ';

Second, if you have forgotten the MySQL database root user password, and how to do it? The method is as follows:

1, close the currently running MYSQLD Service Program: Service mysqld Stop (to add mysqld first to the system services)

2. Use the Mysqld_saft script to start the MYSQLD service in Safe mode (without loading the authorization table)

/usr/local/mysql/bin/mysqld_saft--skip-grant-table &

3, use the null password root user login to the database, reset the root user password

#mysql-u Root

Mysql> Update Mysql.user Set Password=password (' New password ') where user= ' root ';

mysql> flush Privileges;

Note: The above command is case-insensitive

This article is from the "Soldier" blog, please be sure to keep this source http://ganbing.blog.51cto.com/7002794/1217697

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/MySQL/

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.