Home > Database > Mysql Tutorial > Linux mysql forgot password

Linux mysql forgot password

王林
Release: 2023-05-08 18:58:35
Original
795 people have browsed it

MySQL Forgot Password for Linux

MySQL is one of the most commonly used relational database management systems, and Linux is a widely used operating system. On Linux systems, MySQL database is also widely used. The installation and configuration of MySQL is a relatively easy process, but during use or when newbies are learning MySQL, they often encounter the problem of forgetting their passwords. This article will introduce how to solve the problem of forgetting MySQL password under Linux system.

  1. Use the root user to log in to MySQL

In the Linux system, if you want to log in to MySQL through the command line, you need to use the root user and enter the corresponding password. If you forget the MySQL root password, you will not be able to operate through the login command. Therefore, the first step is to log in to MySQL using the root user. The prerequisite is that the MySQL service has been installed on the Linux system.

Enter the terminal and enter the following command:

mysql -u root -p
Copy after login
Copy after login

You will be prompted to enter the password. If you have forgotten the MySQL root password, enter any characters or press Enter directly. At this point, you will be prompted to enter a new password.

  1. Reset the root password of MySQL

In MySQL, the password of the root user is stored in a system table, so you can use SQL commands to modify this directly The value of the password to reset the MySQL root password. The specific steps are as follows:

a. Select the MySQL database

Before using the SQL command to change the password, you first need to select the MySQL database. Enter the following command:

use mysql;
Copy after login

b. Update the password of the root user

In MySQL, the framework has a built-in statement to update the password, which can operate on the root user. Enter the following command:

update user set password=password("新密码") where user="root";
Copy after login

Note that the "new password" here refers to entering a new password to replace the original password.

c. Refresh user permissions

After using the above command to modify the password of the root database, you need to refresh the user permissions for the new password to take effect. Enter the following command:

flush privileges;
Copy after login

d. Exit the MySQL service

After completing the above modification operations, you need to exit the MySQL service and log in again with a new password. At this time, enter the following command:

exit;
Copy after login
  1. Use the new password to log in to MySQL

After completing the above steps, you can use the new password to log in to MySQL again. Enter the following command:

mysql -u root -p
Copy after login
Copy after login

The system will prompt you to enter the password. At this time, enter the modified new password. After entering the correct password, you can perform operations related to the MySQL database.

Summary:

Under the Linux system, forgetting the root password of the MySQL database is not a very troublesome problem. You only need to use SQL commands and some operations in the first step to easily solve it. to reset the password. Through the introduction of this article, I hope to better help Linux system users solve the problem of lost passwords, so that everyone can smoothly perform MySQL-related operations.

The above is the detailed content of Linux mysql forgot password. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template