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

Forgot mysql password in linux

WBOY
WBOYOriginal
2023-05-12 09:06:071362browse

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
  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 &
  1. Access MySQL: Use the following command to access MySQL.
sudo mysql
  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;

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

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
  1. Use the dpkg-reconfigure command: Use the following command to reset the MySQL password.
sudo dpkg-reconfigure mysql-server-5.5

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

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
  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

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!

Statement:
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
Previous article:mysql 64-bit installationNext article:mysql 64-bit installation