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