How MySQL modifies the root account password

Source: Internet
Author: User

How MySQL modifies the root account password


How do I change the root user's password in MySQL database? Here's a summary of some ways to modify the root user password

1: Modify using the Set Password statement

Mysql> Select User ();
+----------------+
| User () |
+----------------+
| Root@localhost |
+----------------+
1 row in Set (0.08 sec)

Mysql> set Password=password (' 123456 ');
Query OK, 0 rows Affected (0.00 sec)

mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)

Mysql> exit



2: Update user table for MySQL database

mysql> use MySQL;
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a

Database changed
mysql> Update user Set Password=password (' QwE123 ') where user= ' root ';
Query OK, 4 rows affected (0.03 sec)
Rows Matched:4 Changed:4 warnings:0

mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)

Mysql> quit



3: Modify with the mysqladmin command

The command is typically mysqladmin-u root-p ' oldpassword ' password Newpass as follows:

[Email protected] ~]# mysqladmin-u root-p ' 123456 ' password ' Qwe123 '
Warning:using a password on the command line interface can is insecure.

Verify that the root password modification is successful

[Email protected] ~]# mysqladmin-u root-p ' 123456 ' password ' Qwe123 '
Warning:using a password on the command line interface can is insecure.



Above is the root password in the case of the root password change, if you forget the root password, how to change the root password?

1: First stop the MySQL service

[[Email protected] ~]# service MySQL stop
Shutting down MySQL. [OK]
[Email protected] ~]# 

Or

[[email protected] ~]#/etc/rc.d/init.d/mysql stop
Shutting down MySQL. [OK]

2: Then use the Mysqld_safe command to start MySQL, update the root account password

--skip-grant-tables: Do not start grant-tables (authorization table), skip permission control.

--skip-networking: Skipping the TCP/IP protocol, only native access (this option is not required.) Can not be used) is not

[Email protected] ~]# mysqld_safe--user=mysql--skip-grant-tables--skip-networking &
[1] 5145
You have new mail in/var/spool/mail/root
[Email protected] ~]# 150709 14:10:53 mysqld_safe Logging to '/var/lib/mysql/db-server.localdomain.err '.
150709 14:10:53 Mysqld_safe starting mysqld daemon with databases From/var/lib/mysql

[[email protected] ~]# mysql-u root MySQL
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a

Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server version:5.6.20-enterprise-commercial-advanced MySQL Enterprise server-advanced Edition (commercial)

Copyright (c), the Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| MySQL |
| Performance_schema |
| Test |
+--------------------+
4 rows in Set (0.00 sec)

mysql> use MySQL
Database changed
mysql> UPDATE user SET Password=password ("Qwe123") WHERE user= ' root '; 
Query OK, 4 rows affected (0.01 sec)
Rows Matched:4 Changed:4 warnings:0

mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)

Mysql> exit
Bye

3: Restart the MySQL service.

The above is the whole content of this article, I hope you can enjoy 

Reference Source: http://www.aichengxu.com/view/61538

How MySQL modifies the root account password

Related Article

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.