Get the App
SLTechnology News&Howtos  ›  Database  › 

I forgot my root password for MySQL. What should I do?

Shulou Source: shulou.com Published: 2022-06-01 17:45:18 10月02日 Update

When we install MySQL, the default root user does not have a password to log in to MySQL. What should we do when we set the password for the root user and forget the password when we log in again?

Local root password reset:

Ideas for solving the problem:

1. Modify the main configuration file / etc/my.cnf to set the authentication of the permission table to be skipped when logging in

2. Restart the service after setting it up

3. Do password-free login on the mysql-server server and update the password of root

4. Modify the / etc/my.cnf main configuration file again

5. Restart the service

6. Log in with a new password

Example:

Environment: centos7 system with MySQL database installed

Steps:

After centos7 installs the mariadb server, mysql enters the database and sets a password for root, and then exits the database

Set password reference blog: https://blog.51cto.com/14181896/2361492

After exiting the database, you cannot enter the database directly with the mysql command. At this time, the password of root is root. Suppose we do not remember the root password of mysql at present, as follows

1. Modify the main configuration file / etc/my.cnf to set the authentication of the permission table to be skipped when logging in

Insert skip_grant_table in the main configuration file

2. Restart the service, and you can access the mysql database without a password

3. Update the password for root

Update mysql.user set password=password ("127") where user='root' and host='localhost' # sets the password to 127,

Flush privileges; # Refresh permissions table

4. Exit the database, comment on the skip_name_table line of the main configuration file, and restart the service again

5. Log in to the database with the newly set password

Login successful!

Tags: Password data database login service file configuration again permissions install user server update authentication what to do success no blog command instance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno MySQL macOS Xiaomi