There are two prerequisites for changing the root password of MySQL if I forget the root password :? You have the permission to modify the MySQL configuration file. You have the permission to restart the MySQL service. modify the configuration file first :? Reference # vimetcmy. cnf? [Mysqld]? Datadirvarlibmysql? Socketvarlibmysqlmysql. sock? Usermysql? # D
There are two prerequisites for changing the root password of MySQL if I forget the root password :? You have the permission to modify the MySQL configuration file. You have the permission to restart the MySQL service. modify the configuration file first :? Reference # vim/etc/my. cnf? [Mysqld]? Datadir =/var/lib/mysql? Socket =/var/lib/mysql. sock? User = mysql? # D
How to solve the problem of forgetting the root password of MySQL
To change the root password of MySQL, there are two prerequisites :?
- You have the permission to modify the MySQL configuration file.
- You have the permission to restart the MySQL service.
First modify the configuration file :?
Reference
# Vim/etc/my. cnf?
[Mysqld]?
Datadir =/var/lib/mysql?
Socket =/var/lib/mysql. sock?
User = mysql?
# Default to using old password format for compatibility with mysql 3.x?
# Clients (those using the mysqlclient10 compatibility package ).?
Old_passwords = 1?
# Disabling symbolic-links is recommended to prevent assorted security risks ;?
# To do so, uncomment this line :?
# Symbolic-links = 0?
[Mysqld_safe]?
Log-error =/var/log/mysqld. log?
Pid-file =/var/run/mysqld. pid
In[Mysqld]AddSkip-grant-tables, That is, the permission verification is skipped .?
Then log on to MySQL and change the root password :?
Reference mysql> use mysql ;?
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 (' ') Where user = 'root ';?
Query OK, 3 rows affected (0.00 sec )?
Rows matched: 3? Changed: 3? Warnings: 0?
Mysql> flush privileges ;?
Query OK, 0 rows affected (0.00 sec )?
Mysql> quit?
Bye?
Then, change the modified configuration file back and restart the service :?
Reference
# Service mysqld restart?
Stop a MySQL instance :????????????????????????????????????? ????????? [OK]?
Start MySQL :????????????????????????????????????? ????????? [OK]?
It's so easy to forget the password of Mysql.
PS: more decisive method :?
Reference
Disable mysqld?
Run the command line mysqld -- skip-grant-tables & password-less login !?
?