Since ubuntu installs different versions of Mysql by default, this problem will occur, resulting in you not knowing what the account password is. This section will solve it for you.
First, if you are an ordinary user (root users can skip this step), you need to find the Mysql file that saves the default account password, the debian.cnf file located under /etc/mysql, enter the directory and find the following information:
Note that the password is randomly generated and different every time. After recording it, we start to reset the password.
If you are a root user, enter Mysql directly in the terminal to enter the database. If you are an ordinary user, enter the account password in the following format to log in based on the account password in the previous step.
mysql -u username -p password
Note that there is no space after -u and -p next to the user and password. For example, for the account password here, enter:
mysql-udebian-sys-maint-pwcVCVuYlHVHaUrnc
The effect after successful login is as follows:
Seeing this box, we can enter various mysql commands here. Entering quit will exit mysql and return to the terminal state.
Next we enter in mysql:
showdatabases;usemysql;updateusersetauthentication_string=PASSWORD(dotcpp)whereuser='root';updateusersetplugin=mysql_native_password;flushprivileges;quit;
Note that there is a semicolon after each sentence to indicate the end of the sentence, where dotcpp indicates the password of the root user. Exit after executing the sequence
Then restart the Mysql service
/etc/init.d/mysqlrestart;
Complete Mysql password reset
We can directly use the new password to log in with the following command
mysql -u username -p password
You can also use this password when connecting to the database in other PHP programs, and you're done.