1. log on to the system as the root user first;
2. Shut down the MYSQL service or process: service mysqld stop/killall mysqld;
3. privileged to start MYSQL:/usr/local/mysql/bin/mysqld_safe -- skip-grant-tables & or mysqld_safe -- skip-grant-tables -- skip-networking & (note: parameter -- skip-grant-tables indicates that the authorization table is skipped; -- skip-networking indicates that TCP/IP connections are not monitored );
4. Then, you can enter MySQL: mysql-u root-p without a password (you can press enter directly when entering the password );
Mysql> use mysql;
Mysql> update user set password = password ('new pw ') where user = 'root' (Note: 'New pw' is your new password, others are copied;
Another method: update mysql. user set password = password ('new pw ') where user = 'root ';
5. Update:
Mysql> flush privileges;
Mysql> quit;
6. End the newly started MYSQL process: killall mysqld or killall-9 mysqld.
7. start MYSQL normally: service mysql start
8. log on to mysql-u root-p with 'new pw.
OK ......
> You can also do the following:
First, modify the MySQL Logon Settings:
# Vi/etc/my. cnf
In the [mysqld] section, add skip-grant-tables.
For example:
[Mysqld]
Datadir =/var/lib/mysql
Socket =/var/lib/mysql. sock
Skip-grant-tables
Save and exit vi.
Restart mysqld and change the password;
Finally, modify the MySQL Logon Settings:
# Vi/etc/my. cnf
Delete the skip-grant-tables added to the [mysqld] section.
Save and exit vi.
Log on to MYSQL again, just like OK ......
This article is from the "colive" blog