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 withdatabases from/var/lib/mysql
|
Step 3: log on to MySQL with an account
|
01
02
03
04
05 |
[root@CentOs5 ~]# mysql -u root
Welcometothe MySQL monitor. Commands endwith ; or\g.
Your MySQL connectionid is1
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
Readingtableinformation forcompletion oftable and column names
You can turn offthis feature toget a quicker startup with-A
Databasechanged
|
Step 5: change the password. Remember to use the password () function to encrypt the password. Do not forget it! Otherwise,
|
01
02
03 |
mysql>updateuser set password=password('admin123')whereuser='root';
Query OK, 1 row affected (0.04 sec)
Rowsmatched: 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 inyour SQL syntax; checkthe manual that corresponds toyour MySQL server version forthe rightsyntax touse near 'previleges'at line 1
mysql> flush privileges;
Query OK, 0 rowsaffected (0.00 sec)
|
Step 7: Exit mysql
Step 8: restart mysql
|
01
02
03
04
05
06 |
[root@CentOs5 ~]# service mysqld restart;
STOPPING server frompid 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
Enterpassword: admin123
Welcometothe MySQL monitor. Commands endwith ; or\g.
Your MySQL connectionid is2
Server version: 5.0.77 Source distribution
Type'help;'or '\h' for help. Type '\c'to clear the buffer.
mysql> quit
Bye
[root@CentOs5 ~]#
|