Several ways to change password in mysql Database and how to forget password
1. Mysql password modification method:
1. Use mysqladmin to modify
# mysqladmin-uroot-p password 'newpass'Enter password: note: if it is the first time to change the password, prompt Enter password: enter directly. If you reset the password, prompt Enter password: enter the old password and enter enter.
2. Enter mysql to change your password
Mysql > set password for 'root'@'127.0.0.1' = password (' newpasswd'); or this: mysql > set password for 'root'@'%' = password (' newpasswd')
3. Use update to edit user table
Mysql > update user set password=password ('newpassword') where user='root' and host='localhost';mysql > flush privileges; Note: don't forget to execute the flush privileges command!
2. How to deal with mysql forgetting password
Description: when mysql is running
1. Add skip-grant-tables under [mysqld] of / etc/my.cnf to restart the mysql process. After restarting successfully, execute # mysql directly to enter mysql, and then modify: mysql > use mysqlDatabase changedmysql > update user set password=password ('newpassword') where user='root' and host='localhost';Query OK, 1 row affected (.01 sec) Rows matched: 1 Changed: 1 Warnings: 0mysql > flush privileges Query OK, 0 rows affected (0.05sec) Note: you can only use the modification method of update, but the method of set cannot be modified successfully in skip-grant-tables mode! 2. Delete skip-grant-tables from my.cnf, restart the mysql process, and enter mysql with a new password.