I often forget various passwords when learning CentOS Linux. This article mainly describes how to forget the MySQL database password when using CentOS. Step 1: run the following code to stop the MySQL server: 0102 [root @ CentOs5 ~] # ServicemysqldstopStoppingMySQL: [OK] Step 2: Use "-ski"
I often forget various passwords when learning CentOS Linux. This article mainly describes how to forget the MySQL database password when using CentOS. Step 1: run the following code to stop the MySQL server: 01 02 [root @ CentOs5 ~] # Service mysqld stop Stopping MySQL: [OK] Step 2: Use "-ski"
I often forget various passwords when learning CentOS Linux. This article mainly describes how to forget the MySQL database password when using CentOS.
Step 1: run the following code to stop the MySQL server
01 02 |
[root@CentOs5 ~]# service mysqld stop
Stopping MySQL: [ OK ]
|
Step 2: Use the "-skip-grant-tables" parameter to restart mysql
01 02 03 |
[root@CentOs5 ~]# mysqld_safe --skip-grant-tables &
[1] 23810
[root@CentOs5 ~]# Starting mysqld daemon with databases from /var/lib/mysql
|
Step 3: log on to MySQL with an account
01 02 03 04 05 |
[root@CentOs5 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
|
Step 4: Change the user database table
01 02 03 04 |
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 -A
Database changed
|
Step 5: change the password. Remember to use the password () function to encrypt the password. Do not forget it! Otherwise,
01 02 03 |
mysql> update user set password = password ( 'admin123' ) where user = 'root' ;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
|
Step 6: refresh the permission table
01 02 03 04 |
mysql> flush previleges;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'previleges' at line 1
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
|
Step 7: Exit mysql
Step 8: restart mysql
01 02 03 04 05 06 |
[root@CentOs5 ~]# service mysqld restart;
STOPPING server from pid file /var/run/mysqld/mysqld.pid
100421 13:44:03 mysqld ended
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
[1]+ Done mysqld_safe --skip-grant-tables
|
Step 9: Log On again with the changed password.
01 02 03 04 05 06 07 08 09 |
[root@CentOs5 ~]# mysql -u root -p
Enter password : admin123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> quit
Bye
[root@CentOs5 ~]#
|