Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to reset root password in MySQL

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces you how to reset the root password in MySQL, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1. Preface

Forget your MySQL root password? Don't worry, it happens to all of us.

In this tutorial, we will show you how to reset your MySQL root password in case you forget your password. This tutorial applies to any modern Linux distribution, such as Ubuntu 18.04, CentOS 7, Debian, and so on.

two。 Preparatory work

Before continuing with the following steps, be sure to log in to the server as a user with sudo privileges.

Depending on the version of the MySQL or MariaDB server you are running on your system, you will need to use different commands to recover the root password.

You can find your mysql version with the following command:

[root@zcwyou] # mysql-- version

If you already have MySQL installed on your system, the output will look like this:

Mysql Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86 / 64) using readline 5.1

Be sure to make a note of the version of MySQL or MariaDB you are running.

3. How to reset the root password for MySQL or MariaDB

Follow these tutorial steps to reset the MySQL password

To change the root password, we first need to stop the MySQL server. To do this, type the following command:

Sudo systemctl stop mysql

How to reset the root password for MySQL or MariaDB

4. Skip the grant authorization table to start the mysql/MariaDB service

When the-- skip-grant-tables option is enabled, anyone can connect to the database server without a password and all permissions.

To start the database server without loading the grant authorization table, type:

[root@zcwyou] # mysqld_safe-- skip-grant-tables &

The & symbol at the end of the above command will cause the program to run in the background, so we can continue to use shell.

5. Log in to the command line interface of `mysql`

You can now connect to the database server as root without prompting you for a password:

[root@zcwyou] # mysql-u root

6. Reset mysql root password

If you have MySQL 5.7.6 and later or MariaDB 10.1.20 and later, run the following command:

Mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY' MY_NEW_PASSWORD'; mysql > FLUSH PRIVILEGES

If the ALTER USER statement does not work, try modifying the user table directly:

Mysql > UPDATE mysql.user SET authentication_string = PASSWORD ('MY_NEW_PASSWORD') mysql > WHERE User =' root' AND Host = 'localhost'; mysql > FLUSH PRIVILEGES

If you have MySQL 5.7.5 and earlier or MariaDB 10.1.20 and earlier, run the following command:

Mysql > SET PASSWORD FOR 'root'@'localhost' = PASSWORD (' MY_NEW_PASSWORD'); mysql > FLUSH PRIVILEGES

In both cases, if all goes well, you should see the following output:

Query OK, 0 rows affected (0.00 sec)

7. Stop the Mysql database and restart normal mode

Now that we have reset the password for the Mysql database, we need to restart to normal mode

Stop the database from running using the following command:

[root@zcwyou] # mysqladmin-u root-p shutdown

Start the mysql database:

[root@zcwyou ~] # systemctl start mysql

Start the MariaDB database

[root@zcwyou ~] # systemctl start mariadb

8. Verify the new password

Verify the new password you just set by entering the following command:

[root@zcwyou] # mysql-u root-p

Prompt you need to enter the new password just set, if there is no accident, you should be able to log in to the database normally.

On how to reset the root password in MySQL to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

  • Oracle 10g installation prompt: operating system version: must be 5.1 or 5.2 what to do?

    Today, this problem occurred during the installation of oracle10g. After multi-party verification, we got this solution. Share it! 1. Search for refhost.xml in the installation directory, and then add the following in the appropriate location. Notice the parenthesis pairing

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report