How to retrieve the mysql password in linux

Source: Internet
Author: User
Tags mysql tutorial

Linux forgot mysql password retrieval method today we mainly talk about how to handle linux forgot mysql password. Below are five methods for restoring linux forgot mysql password.

How to retrieve the password of the linux forgot mysql tutorial
Today, we will mainly talk about how to deal with linux forgetting the mysql password. Below we provide five methods to retrieve the linux forgetting the mysql password.
Method 1:

#/Etc/init. d/mysql stop
# Mysqld_safe -- user = mysql -- skip-grant-tables -- skip-networking &
# Mysql-u root mysql
Mysql> update user set password = password ('newpassword') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
#/Etc/init. d/mysql restart
# Mysql-uroot-p
Enter password: <enter the new password newpassword>
Mysql>

Method 2:
Directly use the username and password provided in the [client] section of the/etc/mysql/debian. cnf file:

# Mysql-udebian-sys-maint-p
Enter password: <enter the password in the [client] section>
Mysql> update user set password = password ('newpassword') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
# Mysql-uroot-p
Enter password: <enter the new password newpassword>
Mysql>

Method 3:
I have not tested this method, because the default password of my root user has been modified by me. If you have time to test it, let me know the result. Thank you !!

# Mysql-uroot-p
Enter password: <enter the password provided in [client] in the/etc/mysql/debian. cnf File>


Method 4

The method is as follows: 1. Disable mysql service/etc/init. d/mysqld stop 2. Use the-skip-grant-tables option to start the mysql service. You can modify/etc/inin. d/mysqld script to add this option at the startup location, vi/etc/init. d/mysqld
The method is as follows:

1. Disable the mysql service.
/Etc/init. d/mysqld stop

2. Use the-skip-grant-tables option to start the mysql service. You can modify the/etc/inin. d/mysqld script startup location to add this option,
Vi/etc/init. d/mysqld

Add -- skip-grant-tables in the following statement to run the startup command.
/Usr/bin/mysqld_safe -- skip-grant-tables -- datadir = "$ datadir" -- socket = "$ socketfile"
-- Log-error = "$ errlogfile" -- pid-file = "$ mypidfile"

Adding -- skip-grant-tables indicates that the permission table authentication is skipped when the mysql service is started. After mysql is started, the root user connected to mysql does not need a password.

3. Restart the mysql service.
/Etc/init. d/mysqld start

4. Modify the password of the root user;

Mysql> update mysql. user set password = password ('000000') where user = root;
Mysql> flush privileges;
Mysql> quit

5. Restart mysql to log on with the new password.

Mysql

Mysql-u root-p
Enter Password 123456

6. Disable the mysql service.
/Etc/init. d/mysqld stop

7. Modify the/etc/init. d/mysqld modified in step 1 to keep it unchanged. That is, cancel the -- skip-grant-tables statement.
8. Restart the mysql service.

/Etc/init. d/mysqld start
Unix

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.