MySQL database change password & forgot password

Source: Internet
Author: User

Method 1 : with SetPassword Command

MySQL -uroot

mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Newpass ');

Method 2 : With mysqladmin

if Root Password has been set, using the following methods mysqladmin-u root password "Newpass"

Mysqladmin-u root Passwordoldpass "Newpass"

Method 3 : with UPDATE Direct Editing User Table

Mysql-u Root

mysql> use MySQL;

mysql> UPDATE User SetPassword = PASSWORD (' newpass ') WHERE user = ' root ';

mysql> FLUSH privileges;

Method 4 : When you forget the root password, you can manipulate the database as follows:

First step: Stop the database First, execute the following command:

apt-get or yum install mysql can be executed directly mysql.serverstop command

If the database is compiled and installed, you need to enter MySQL the command directory bin/ Down,

Execution: ./mysql.server Stop or servicemysqld Stop

Step Two: Modify my.cnf

Use Vim Command Open MySQL configuration file my.cnf

in the mysqld The process configuration file is added Skip-grant-tables , after the add is complete, execute WD saved.

Step three: Restart the database

Restarting a database with command-line tools

Service mysqld Restart

Fourth Step: Modify Root Password

After restarting the database can be directly logged in without a password:
MySQL -u root mysql
mysql> UPDATE user SET Password=password ("New password") WHERE user= ' root ';
mysql>flush privileges;
# will password () newpassword character changed to your own password.

mysqld_safe--skip-grant-tables&

Mysql-u Root MySQL

mysql> UPDATE User Setpassword=password ("New PASSWORD") WHERE user= ' root ';

mysql> FLUSH privileges;

Fifth step: Restart the database
After the password modification is complete, the my.cnf files that are added to the Skip-grant-tables Comment or delete the statement, and then restart.


This article from the "11637266" blog, reproduced please contact the author!

MySQL database change password & forgot password

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.