Mysql password recovery in Linux

Source: Internet
Author: User

If Mysql is not accessed for a period of time, you may forget the access password. What should I do? reinstall mysql? The cost is too high. Here we will introduce two methods to restore the password.

Method 1: Because the Mysql password is stored in the user table in the mysql database, we only need to copy and overwrite the user table with the known password.

In Linux, there are three user table files in the/var/lib/mysql/directory: user. frm, user. MYD, and user. MYI. They represent:

User. frm // user Table Style File
User. MYD // user table data file

User. MYI // user table index file

For the sake of insurance, we will first back up the files related to the three user tables ,,

Back up three related files in the user table

Then we copy the three files in the user table in the mysql database with the password. Then we can use ls to view the six user table files.

In this case, you only need to restart the mysql service to access the Mysql database with a known password.

Restart command: service mysql restart or

/Etc/init. d/mysql restart

Now we can access the Mysql database with a known password.

Content navigation

Method 2:

The first method is to restore the password of another Mysql database without such a known password. How can we recover the database? We use a method described in the Mysql Chinese Reference Manual, which involves several steps:

1: Send the kill command to the mysqld server to disable the mysqld server (not kill-9). The files that store the process ID are usually located in the directory of the MYSQL database.

Killall-TERM mysqld // you must be a UNIX root user or your running

SERVER.

2: Use the '-- skip-grant-tables' parameter to start mysqld. (See/usr/bin/safe_mysqld -- skip-grant-tables in LINUX and c: mysqlbinmysqld -- skip-grant-tables in windows;

Result of steps 1 and 2

3: Then you can log on to the mysqld server without a password. At this time, the Mysql password is the same as the one you just installed and is empty. Now we can use mysqladmin to change the mysql password in figure 6.

4: load the permission table. You can use mysqladmin flush-privileges to refresh the permission table.

Use mysqladmin to load the permission table

5: log on with the new password.

Mysql is a powerful database that requires more practice in practice. This article describes how to install Mysql and the most basic commands for accessing and changing passwords, finally, we will introduce two methods to restore the Mysql password. Hope to help you.

  1. Delete MySQL database data recovery in Linux EXT3
  2. Add an ODBC driver for MySQL in Ubuntu
  3. LAMP (Linux + Apache + Mysql + PHP) Environment Construction

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.