Docker modify the MySQL password in the container and restart the container bug

1. Correct operation

  1. View container id
docker ps
  1. Enter the MySQL container
docker exec -it 容器id /bin/bash
  1. Login to MySQL
mysql> mysql -u root -p
  1. Change MySQL password
mysql> SET PASSWORD FOR 'root' = PASSWORD('密码');
  1. Modify the local MySQl password
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('密码');
  1. 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)
insert image description here

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

Guess you like

Origin blog.csdn.net/weixin_42516475/article/details/129405703