Solution: 1. After logging in to the database, use the "select host, user from user;" statement to query users and permissions; 2. Use "grant select, update, insert, delete on mas.* to create a new user @localhost identified by "password";" statement adds a user with normal permissions and logs in to the mysql database again.
The operating environment of this tutorial: linux7.3 system, mysql8.0.22 version, Dell G3 computer.
When I started to use Linux to connect to the mysql database, a 1045 error occurred. When this problem occurs, it should be that the user has been denied access by the database, and we should open up permissions for your database.
1. Query database user permissions
Log in to the database and enter the linux command
mysql -uroot -padmin
Log in to your database and enter the user name and password
Use the database to query permissions
mysql> use mysql;
mysql> select host,user from user;
You can query users and permissions
2. If you want to remote mysql server, you need to add normal permissions The user
mysql> grant select,update,insert,delete on mas.* to root@localhost identified by "admin";
grant select,update,insert,delete on mas.* to create a new user @localhost identified by "password";
The meaning of this command is : Create a new user root, and only allow this user to log in locally (localhost), the password is admin, and grant it the select, update, and insert permissions on all tables in the mas database. We have a mas library here, so mas.* represents all tables under the mas library. Now the root user can log in to mysql, but it can still only log in locally.
If you want the root user to log in to mysql remotely, you need the following command:
mysql> update user set host = '%' where user = 'root';
We can also directly give the user permissions
grant all on *. * to username@"%" identified by "password";
##flush privileges; refresh privileges
Recommended learning:The above is the detailed content of How to solve the 1045 error of mysql in linux. For more information, please follow other related articles on the PHP Chinese website!