For the process of changing the root password of MySQL in Linux, we can find a lot on the Internet, which is:
# Killall mysqld // interrupt the currently running MySQL process
# Mysqld_safe -- skip-grant-tables & // start the Security Mode
# MySQL // directly access MySQL without a password
--> Use MySQL // use a MySQL database instance
--> Update user SET Password = PASSWORD ('000000') where user = 'root ';
// Change the root user password to 123
Restart your computer and enter the following command:
Mysql-u root-P
123
You can access the MySQL database.
------------------------------------------------------------------------------
The above method was found on the internet, but when I started the security mode, I encountered a new problem:
Invalid 'mysql' user
Starting mysqld daemon with databases from/opt/MySQL/Data
Stopping server from PID file/opt/MySQL/data/localhost. localdomain. PID
There will be three lines of error information, searched for N on the Internet for a long time, and finally solved the problem. The solution is as follows:
For 'invalid user', my solution is:
# Groupadd MySQL
# Useradd-G MySQL
The next two lines are mainly about the permission of the data directory. When the database is started, a new file is generated to the directory, and the command is terminated because the permission is not allowed.
However, on different computers, the directory names are sometimes different and the following displays:
Starting mysqld daemon with databases from/opt/MySQL/var
Stopping server from PID file/opt/MySQL/var/localhost. localdomain. PID
Modify permission: chmod-r 1777 data/
Or chmod-r 1777 var/
Then, go through the password change process.
Note: The/opt/MySQL/data/localhost. localdomain. Err file is a MySQL error log file. If you cannot solve the problem, open this file to view the error log.