Home > Database > Mysql Tutorial > Forgot mysql password in linux

Forgot mysql password in linux

WBOY
Release: 2023-05-12 09:06:07
Original
1351 people have browsed it

In the process of using the Linux operating system, we often encounter the situation of forgetting the MySQL password. What should we do at this time? This article will introduce several methods to solve this problem.

Method 1: Use mysqld_safe to start MySQL

  1. Stop the MySQL service: Use the following command to stop the MySQL service.
sudo /etc/init.d/mysql stop
Copy after login
Copy after login
  1. Start the MySQL service: Use the following command to start the MySQL service and add the --skip-grant-tables parameter after the command.
sudo mysqld_safe --skip-grant-tables &
Copy after login
  1. Access MySQL: Use the following command to access MySQL.
sudo mysql
Copy after login
  1. Change password: After entering MySQL, use the following command to change the password.
use mysql;
update user set password=PASSWORD("new_password") where User='root';
flush privileges;
Copy after login

The "new_password" is the new password you want to set. After the setting is successful, you can use the quit command to exit MySQL, and then use the following command to restart the MySQL service.

sudo /etc/init.d/mysql restart
Copy after login
Copy after login

Method 2: Use the dpkg-reconfigure command

  1. Stop the MySQL service: Use the following command to stop the MySQL service.
sudo /etc/init.d/mysql stop
Copy after login
Copy after login
  1. Use the dpkg-reconfigure command: Use the following command to reset the MySQL password.
sudo dpkg-reconfigure mysql-server-5.5
Copy after login

The option to reset the MySQL password will appear.

  1. Restart the MySQL service: Use the following command to restart the MySQL service.
sudo /etc/init.d/mysql restart
Copy after login
Copy after login

It should be noted that the dpkg-reconfigure command is only valid on Debian systems.

Method 3: Use the MySQL management tool

In addition to the above two methods, you can also use the MySQL management tool to reset the MySQL password. Here are two commonly used MySQL management tools.

  1. phpMyAdmin: phpMyAdmin is a Web-based MySQL management tool. You can use a Web browser to manage MySQL databases through phpMyAdmin. First you need to install phpMyAdmin, use the following command to install it.
sudo apt-get install phpmyadmin
Copy after login
  1. MySQL Workbench: MySQL Workbench is a cross-platform MySQL database management tool. MySQL Workbench can be installed using the following command.
sudo apt-get install mysql-workbench
Copy after login

To use the MySQL management tool to reset the password, you need to provide the user name and password of the MySQL administrator. Before resetting your password, make sure you have backed up your MySQL database.

To sum up, forgetting MySQL password is not a troublesome problem and can be solved by the above methods. Before operating, be sure to back up the database to avoid losing important data.

The above is the detailed content of Forgot mysql password in linux. 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