Mysql changes the root account password method _mysql

Source: Internet
Author: User
Tags flush

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

1: Using the Set Password statement to modify

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 the user table for the MySQL database

mysql> use MySQL;
Reading table information for completion of table and column names you can turn out this feature to get
a quicker star Tup 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
 
;
Query OK, 0 rows Affected (0.00 sec)
 
Mysql> quit

3: Use the mysqladmin command to modify

The commands are generally mysqladmin-u root-p ' oldpassword ' password Newpass as follows:

[Root@db-server ~]# mysqladmin-u root-p ' 123456 ' password ' Qwe123 '
warning:using ' a password on the command line int Erface can be insecure.

Verify that the root password modification is successful

[Root@db-server ~]# mysqladmin-u root-p ' 123456 ' password ' Qwe123 ' warning:using '
a password on the command line inte Rface can be insecure.


The above is to know the root password to modify the root password, if you forget the root password, how to modify the root password it?

1: First stop MySQL service

[root@db-server ~]# service MySQL stop
shutting down MySQL. [OK]

Or

[Root@db-server ~]#/etc/rc.d/init.d/mysql stop
shutting down MySQL. [OK]


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

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

--skip-networking: Skip TCP/IP protocol, only on native access (this option is not required.) Yes, you can.

[Root@db-server ~]# mysqld_safe--user=mysql--skip-grant-tables--skip-networking & [1] 5145 you have new mail in/v Ar/spool/mail/root [root@db-server ~]# 150709 14:10:53 mysqld_safe to ' Logging
Db-server.localdomain.err '. 150709 14:10:53 Mysqld_safe starting mysqld daemon with databases From/var/lib/mysql [root@db-server ~]# mysql-u Root MySQL Reading table information for completion of table and column names you can turn out this feature to get a quicker st Artup 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 Edi tion (commercial) Copyright (c), 2014, Oracle and/or its affiliates.
 
All rights reserved. Oracle is a registered trademark to Oracle Corporation and/or its affiliates.
 
The other names may is 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;

 Query OK, 0 rows Affected (0.00 sec) mysql> Exit Bye

3: Restart the MySQL service.

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

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.