Cannot find the created database after logging in to mysql

Cannot find the created database after logging in to mysql

Recently, when I set up a remote server on Linux, I logged in to mysql the next day and found that the newly created database disappeared ,
and the root password was obviously changed, but you can log in directly without entering the password.
There are two issues involved:

1. Reasons for the disappearance of the database

An anonymous user exists in the user table . Anonymous users do not need to enter a password, just press Enter to log in. And the initial permissions of anonymous users cannot access root's database and mysql database, so they cannot see other databases.
Anonymous users: users with empty usernames

2. The reason why you can directly log in after changing the password

After modifying the user table in the mysql database, you need to use flush privilegescommands to update the database configuration. Otherwise, the modified content will not take effect immediately.

solution

First close the mysql service.
service mysqld stop
Then skip the authorization form, so that you can enter mysql without entering a password.
mysqld_safe --skip-grant-table
Sometimes the code window will not give the end of execution feedback after executing this code. You can open a new window to continue the operation, and I use Ctrl+Zit directly to end the execution and continue the operation also successfully.
Use the following command to enter the database
mysql -u root mysql

At this time, you should be able to see the database created before
and then delete all anonymous users in the user table.

delete from mysql.user where user='';

If you forget the root password, you can change the root password at this time.
Finally, don't forget to use the following command to refresh the configuration. Make the changes just now take effect.
flush privileges
After that, you can restart the database service and log in to mysql as root or your own user.
service mysqld restart

Does it help you? Like it~

Guess you like

Origin blog.csdn.net/qq_42068856/article/details/109316080