MySQL Change password and forget root password

Source: Internet
Author: User

1. Close the database

Script: [[email protected] etc]# service MySQL stop

2. Use script: Mysqld_safe--skip-grant-tables start Database

Starting a database with/usr/bin/mysqld_safe--skip-grant-tables&

3. Use a blank password to enter the database (MySQL command directly after the return)

[[email protected] ~]# MySQL

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 3

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>

4. Use the UPDATE statement to change the root password

mysql> UPDATE Mysql.user SET

-Password=password (' root ')

, where

-user= ' root ' and host= ' localhost ';

5. Close the database and start the database again in the normal way

[[Email protected] ~]# service MySQL restart;

Shutting down MySQL. success!

Starting MySQL. success!

[[email protected] ~]# MySQL

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

[Email protected] ~]# mysql-p

Enter Password:

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 2

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>

MySQL Change password and forget root password

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.