MySQL root password forgotten after reset method

Source: Internet
Author: User

What if I forget the root password of MySQL?

We do not set the password for MySQL by default, as follows

Default login for MySQL

[Email protected] ~]# Mysql-uroot

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

Your MySQL Connection ID is 1

Server Version:5.1.40-log MySQL Community Server (GPL)

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

Mysql>quit

Bye

Normally, for security reasons, we should set up a password for MySQL.

[Email protected] ~]# mysqladmin-uroot password ' lamlinux '

Setup is complete, we will login again to enter the password

[Email protected] ~]# Mysql-uroot-plamlinux

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

Your MySQL Connection ID is 3

Server Version:5.1.40-log MySQL Community Server (GPL)

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

Mysql>quit

Bye

What if we forget the password and do not log on to MySQL?

Initialize the password , reset one,

Enter configuration file

[Email protected] ~]# VIM/ETC/MY.CNF

Add a sentence under ' Slow query '

skip-grant (Skip Authorization)

: Wq

Restart MySQL

[Email protected] ~]#/etc/init.d/mysqld restart

Shutting down MySQL. success!

Starting MySQL. success!

Initialization complete

Can directly use "mysql" command, do not need to enter the-p password, you can directly into MySQL,

[[email protected] ~]# MySQL

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

Your MySQL Connection ID is 1

Server Version:5.1.40-log MySQL Community Server (GPL)

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

Mysql>

Then go to use MySQL library

mysql> Use MySQL

No connection. Trying to reconnect ...

Connection Id:2

Current database: * * * NONE * * *

Database changed

Then go to update a table, that is, change the root user's password

mysql> Update user set Password=password ('lam2linux') where user= ' root ';

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect ...

Connection Id:4

Current Database:mysql

Query OK, 3 rows affected (0.01 sec)

Rows Matched:3 Changed:3 warnings:0

From the information we see Query OK, 3 rows affected (0.01 sec) shows that the 3rd line has changed ,

Use the following command to view the change information

Mysql>SELECT * from user where user= ' root ' \g;

Quit MySQL

Mysql>exit

Let's get rid of the "skip-grant" in the MySQL config file.

[Email protected] ~]# VIM/ETC/MY.CNF

Remove Skip-grant

: Wq

Restart MySQL

[Email protected] ~]#/etc/init.d/mysqld restart

Shutting down MySQL. success!

Starting MySQL. success!

log in to MySQL again need to enter a password

[Email protected] ~]# Mysql-uroot-plam2linux

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

Your MySQL Connection ID is 2

Server Version:5.1.40-log MySQL Community Server (GPL)

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

Mysql>

At this point, after the password has been modified and successfully signed in


MySQL root password forgotten after reset method

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.