Ubuntu20 solves the problem of Access denied for user 'root'@'%to database 'xxx' in the database

Recently, an error occurred when assigning mysql permissions. The built-in database mysql version of this virtual machine is 8, so mysql prompts "Access denied for user 'root'@'%" when reassigning permissions. The reason for the error is that the reload permission is withdrawn, resulting in failure Reassign permissions, and other similar permission issues can also refer to this method. The original low version of the database or the version below Ubuntu18 is difficult to cause many problems such as database permission errors.

You can refer to the online tutorial ( https://blog.csdn.net/m0_54849873/article/details/126076063 ) for the correct creation of the database and the delineation of database permissions above 8.0. This blog is very detailed and thorough.

    • Create database Mysql user

Enter mysql and use the account password to log in to enter the main interface MySQL command line page.

mysql -uroot -p

After entering the database interaction line, create a user with administrator privileges, the code is as follows. Here it means to create a user network that does not restrict ip login. The password of this user is 123456, and % means that ip login is not restricted (if you use a specific ip address, you can replace it with an address):

create user 'network'@'%' identified by 'network';

After creating a user network, you need to refresh the privileges privileges, otherwise errors may occur, and the code for refreshing the privileges is relatively simple and clear

flush privileges;

2 You can use navicat to log in and connect users when you create a new connection locally

If the connection is displayed normally, the page shows that the local connection is successful~~. At this time, when you open it, you will find that there are only two databases, information_schema and performance_schema. The picture below shows the picture that I have successfully implemented database authorization and successful creation.

3. User empowerment

After completing the above basic work, empowerment can be realized. The main reasons for the error are:

1. Because the version above Mysql8 cannot use the overall statement of grant all privileges to create at one time, otherwise there will be a version error report.

This means that the user network is given all permissions to all tables in the database network (this is the database I created before) with grant option means that the user can grant permissions to other users, but cannot exceed the permissions of the user, you can refer to the above tutorial to realize this function.

The core SQL code for empowerment is:

grant all privileges on network.* to 'network'@'%' with grant option;
2. The main reason for the second type of error is that the way to enter the database is incorrect. You must use the root administrator account to enter, otherwise there will be similar reasons for insufficient permissions. For example, similar reasons for access denied appear:

Solution:

exit //退出数据库

Log in to MySQL using the root command after exiting:

 mysql -uroot -p(密码)

After entering, use the above authorization command again to complete the authorization management of this database and successfully solve the above problems. This is the cause of the problems that often occur when the database is built.

Guess you like

Origin blog.csdn.net/qq_49491645/article/details/128862875