Overview:
In the production environment, for the MySQL database service I need to control and password control, the main prevention of arbitrary host, any user malicious login operation, but sometimes we do these security policy work, there will be forgotten password, or password is malicious modification, now said the situation is likely to occur, What should I do with you when these anomalies arise? Here's how MySQL password is initialized:
MySQL Password initialization recovery method (1)-- Skip the Authorization table login method via the MY.CNF configuration file
1. Stop MySQL service (recommended to stop MySQL service first)
# Service Mysqld Stop
2. Modify the MY.CNF configuration file to add "skip-grant-tables" option
# Vim/etc/mysql/my.cnf[mysqld]skip-grant-tables
3. Start the MySQL service
# service Mysqld Start
4. Log in to MySQL to change the root password
MySQL > Use mysql;mysql > UPDATE user SET Password = Password (' gzsamlee-mysql ') WHERE user = ' root '; MySQL > FLUSH privileges;
5. Delete or comment the "skip-grant-tables" option in the MY.CNF configuration file
# Vim/etc/mysql/my.cnf[mysqld] #skip-grant-tables
6. Restart the MySQL service to take effect on the new password
# Service Mysqld Restart
MySQL Password initialization recovery method (2)-- Skip the Authorization table login method by starting the service
1. Stop the MySQL service
# Service Mysqld Stop
2. Modify the configuration file to add--skip-grant-tables--skip-networking
# vim/etc/init.d/mysqld $bindir/mysqld_safe--skip-grant-tables--skip-networking--datadir= "$datadir"--pid-file= "$ Mysqld_pid_file_path "$other _args >/dev/null 2>&1 & wait_for_pid created" $! " "$mysqld _pid_file_path"; Return_value=$?
3. Start the MySQL service
# service Mysqld Start
4. Modify the Administrator password
MySQL > Use mysql;mysql > UPDATE user SET Password = Password (' gzsamlee-mysql ') WHERE user = ' root '; MySQL > FLUSH privileges;
5. Stop the MySQL service
# Service Mysqld Stop
6. Modify the configuration file remove--skip-grant-tables--skip-networking
# vim/etc/init.d/mysqld $bindir/mysqld_safe--datadir= "$datadir"--pid-file= "$mysqld _pid_file_path" $other _args > /dev/null 2>&1 &wait_for_pid created "$!" "$mysqld _pid_file_path"; Return_value=$?
7. Start the MySQL service
# service Mysqld Start
This article is from the "Opensamlee" blog, make sure to keep this source http://gzsamlee.blog.51cto.com/9976612/1792941
(--1--) forgot MySQL password processing method in Linux environment