1. Correct operation
- View container id
docker ps
- Enter the MySQL container
docker exec -it 容器id /bin/bash
- Login to MySQL
mysql> mysql -u root -p
- Change MySQL password
mysql> SET PASSWORD FOR 'root' = PASSWORD('密码');
- Modify the local MySQl password
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('密码');
- exit mysql
mysql> quit
2. Record the bugs encountered
After changing the password, there is no need to restart the container, the password will still take effect, but this problem will only occur after restarting!
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
After review and practice: you only changed the root password of other host connections, and the root password of localhost did not change
Explanation : Click the mysql database in the connection to view the user table in it, as shown in the figure below.
'root'@'localhost' refers to the root user accessed by this machine, and 'root' refers to the root user accessed by other addresses (for example: navicate)
Solution:
1. Online method: modify the file step by step to solve
2. Personal method: the premise is that you have mounted the data volume, then directly delete your mysql container and create a new one (this is convenient and fast)
https://www.cnblogs.com/callbin/p/17089407.html
https://jiuaidu.com/jianzhan/972512/
https://www.likecs.com/show-308249379.html