1) if you have not forgotten the password, you can use update to directly edit the user table to change the password:
Enter mysql-u Root
Mysql> use MySQL;
Mysql> Update user SET Password = PASSWORD ('newpass') where user = 'root ';
Mysql> flush privileges;
Or
/Etc/init. d/MySQL stop
/Etc/init. d/MySQL start
2) If you have forgotten your password:
#/Etc/init. d/MySQL stop 1. End the currently running MySQL process.
#/Usr/bin/mysqld_safe -- skip-grant-Tables 2. Run in MySQL security mode and skip permission verification.
# Mysql-u root 3. restart a terminal to log on to MYSQL as the root user.
Mysql> use MySQL; 4. Modify the root user password.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed
Mysql> Update user SET Password = PASSWORD ('root') where user = 'root ';
Query OK, 3 rows affected (0.00 Sec)
Rows matched: 3 changed: 3 warnings: 0
Mysql> exit
#/Etc/init. d/MySQL restart 5. End MySQL security mode and run MySql in normal mode.
Mysql> Update mysql. User SET Password = PASSWORD ('new password') where user = 'root ';
6. Try your new password.
Mysql> flush privileges;
Mysql> quit
Reference recommendations:
How does Ubuntu modify the MySQL account and password?
MySQL command operation
MySQL common syntax Summary
Summary of common MySQL database commands
Summary of MySQL Character Set garbled characters
10 outstanding nosql Databases