Today, I encountered a bad problem: I forgot my password when I used MySQL for a long time to create a database. This problem is also very common! To modify the MySQL root Password, you have two prerequisites: You have the permission to modify the MySQL configuration file, and you have the permission to restart the MySQL service. modify the configuration file first: Reference # vimetcmy. cnf [mysqld] datadirvarli
Today, I encountered a bad problem: I forgot my password when I used MySQL for a long time to create a database. This problem is also very common! To modify the MySQL root Password, you have two prerequisites: You have the permission to modify the MySQL configuration file, and you have the permission to restart the MySQL service. First, modify the configuration file: Reference # vim/etc/my. cnf [mysqld] datadir =/var/li
Today, I encountered a bad problem: I forgot my password when I used MySQL for a long time to create a database. This problem is also very common!
There are two prerequisites for modifying the MySQL root Password:
- 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]Add
Skip-grant-tablesTo skip permission verification.
Then log on to MySQL and change the root password:
Reference
# Mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3
Server version: 5.0.95 Source distribution
Copyright (c) 2000,201 1, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.
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, modify the configuration file and restart the service:
Reference
# Service mysqld restart
Stop MySQL: [OK]
Start MySQL: [OK]
Success!
PS: more decisive method:
Reference
Disable mysqld
Execute mysqld -- skip-grant-tables & password-free logon on the command line!