1. mysqladmin-uroot-poldpassword password newpassword
2. mysql> update mysql. user set password = PASSWORD ('new password') where User = 'root ';
Mysql> flush privileges;
Mysql> quit
3. mysql-u root mysql
Mysql> UPDATE user SET password = PASSWORD ("new password") WHERE user = 'name ';
Mysql> flush privileges;
Mysql> QUIT
4. You can modify the MY. ini file in the MYSQL folder.
5. Use the set password statement,
Mysql> set password for myuser @ localhost = PASSWORD ('mypasswd ');
6. Use the GRANT... identified by statement
Mysql> grant usage on *. * TO myuser @ localhost identified by 'mypassword ';
In windows:
Open the command line window and stop mysql service: Net stop mysql
Install MySQL to start mysql. Use mysqld-nt.exe to start MySQL in the bindirectory. Run mysqld-nt -- skip-grant-tables in the command line window.
Then, open a command line window and execute mysql. You do not need to enter a password.
> Use mysql
> Update user set password = password ("new_pass") where user = "root ";
> Flush privileges;
> Exit
Use the task manager to locate the mysqld-nt process and end the process!
After restarting the mysql-nt service, you can log on with a new password.
In linux:
If MySQL is running, killall-TERM mysqld is first killed.
Start MySQL: bin/safe_mysqld -- skip-grant-tables &
You can access MySQL without a password.
Then
> Use mysql
> Update user set password = password ("new_pass") where user = "root ";
> Flush privileges;
Kill MySQL again and start MySQL in a normal way.
1) Stop mysql instances in windows Services
2) use the-skip-grant-tables parameter to start mysql. In this mode, you can log on to mysql without the root password.
Mysqld-max-nt-skip-grant-tables
3) log on to mysql and change the password.
C: \ Documents ents and Settings \ binzhang> mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 1 to server version: 5.0.27-community-max-nt
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql> use mysql;
Database changed
Mysql> update user set password = password ("root") where user = "root ";
Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0