Navicat remote connection, mysql in Docker, an error is reported when creating a new database: 1044 -Access denied for user 'root'@'%' to database

 This error means that the root user does not have permission to access the specified database

 The solution is to re-empower

1. Access the MySQL command line interface inside the Docker container

docker exec -it mysql mysql -u root -p

2. Enter the root user password

Note :

The password will not be displayed, enter it after entering

3. Switch database

use mysql;

4. Update the column in the table host to set the root user's mysql.user value to . '%'

update user set host='%' where user='root';

Note :

        By default, the root user in MySQL is only allowed to connect from the local computer (ie localhost). However, by updating the host column to '%', the root user is allowed to connect from any host, but may be a security risk. If you want to restrict root access to specific hosts, you can replace '%' with the appropriate hostname or IP address.

 

5. Grant the root user all privileges to all databases and tables in the MySQL server and be able to connect from any host ('%').

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

 6. After exit exit, restart the container with docker restart mysql to solve the problem

 

Guess you like

Origin blog.csdn.net/m0_74421344/article/details/130977850