In Linux, MySQL forgets the root user password.

Source: Internet
Author: User

In Linux, MySQL forgets the root user password.

Today, when receiving a MySQL server, I found that I forgot the password of the root user of MySQL. I found that no root user password exists in various documents. Therefore, I need to modify the password of the root user.

First, make sure that the server is in a secure state, that is, no one can connect to the MySQL database at will. Because during the resetting of the MySQL root Password, the MySQL database is completely out of the password-free status, other users can also log on and modify the MySQL information at will. The safest status is to operate on the server Console and unplug the network cable.

1. Modify MySQL Logon Settings:
Add the skip-grant-tables in the [mysqld] segment
# Sed-I '/mysqld/a \ skip-grant-tables'/etc/my. cnf

2. Restart mysqld.
# Service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!

3. log on to and modify the MySQL root Password
#/Usr/bin/mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 1
Server version: 5.6.19 Source distribution

Copyright (c) 2000,201 4, Oracle and/or its affiliates. All rights reserved.

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

Mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed

Mysql> UPDATE user SET Password = password ('bkjia ') WHERE User = 'root ';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3 Changed: 3 Warnings: 0
 
Mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

Mysql> quit
Bye

4. Modify the MySQL Logon Settings
Delete the skip-grant-tables added to the [mysqld] section.
# Sed-I "/skip-grant-tables/d"/etc/my. cnf

5. Restart mysqld.
# Service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!

At this time, you can use root/bkjia to log on.

How can I forget the root password of MySQL in Linux?

Solution for Windows/Linux MySQL to forget the root password

How to solve the problem of forgetting the root password of MySQL

Change the root password for MySQL

How to reset the root password of the MySQL server in Ubuntu

Restore the MySQL root Password under Red Hat

This article permanently updates the link address:

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.