Reset MySQL Database Password in CentOS

Source: Internet
Author: User
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

01

02

mysql> quit

Bye

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 ~]#


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.