Home  >  Article  >  Database  >  How to change the user password of MySQL in the docker container

How to change the user password of MySQL in the docker container

WBOY
WBOYforward
2023-05-29 21:34:044800browse

1. View the started MySQL container id

docker ps |grep mysql

How to change the user password of MySQL in the docker container

2. Enter the started MySQL container

docker exec -it a00ba5071c1e /bin/bash

How to change the user password of MySQL in the docker container

3. Modify the MySQL configuration file

Add skip-grant-tables code in the last line ( //Skip the password verification of mysql)

(if there is no password in the container For the vim command, you can use the commands apt-get update , apt-get install vim to download and install vim)

vim /etc/mysql/conf.d/docker.cnf

How to change the user password of MySQL in the docker container

4. Restart the database

service mysql restart

How to change the user password of MySQL in the docker container

5. Restart the MySQL container

docker restart a00ba5071c1e

How to change the user password of MySQL in the docker container

6. Enter the started MySQL container again

docker exec -it a00ba5071c1e /bin/bash

How to change the user password of MySQL in the docker container

6. Use the statement mysql -u root -p statement

to log in to the database without entering a password, just press Enter

mysql -u root -p

How to change the user password of MySQL in the docker container

7.Use MySQL database

use mysql

How to change the user password of MySQL in the docker container

8.Update user password

update user set authentication_string=password('123') where user="root";

How to change the user password of MySQL in the docker container

9. Exit mysql

How to change the user password of MySQL in the docker container

10. Edit the mysql configuration file again

Delete the just added skip-grant-tables

vim /etc/mysql/conf.d/docker.cnf

How to change the user password of MySQL in the docker container

11. Restart mysql again

service mysql restart

How to change the user password of MySQL in the docker container

12. Restart the docker container again

docker restart a00ba5071c1e

How to change the user password of MySQL in the docker container

The above is the detailed content of How to change the user password of MySQL in the docker container. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete