Docker | Docker install and run Mysql 5.7.31 container and change the database password

One, install Docker

See article: https://blog.csdn.net/y1534414425/article/details/107872715

2. Pull the Mysql 5.7.31 image

docker pull mysql:5.7.31

Three, run Mysql 5.7.31

docker run -d --name myMysql -p 9506:3306 -v /data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Gerenfaka mysql:5.7.31

Parameter resolution::
-dRun the container in the background, and return the container ID
--name myMysql: Specify a name for the container
-p: Specify port mapping, the format is: host (host) port: container port
-v: bind a volume, host directory /data/mysql is mapped to the container /Var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456: set environment variables
mysql:5.7.31: use mirror mysql:5.7.31

Fourth, modify the database password

1. At this point run docker pscan be seen running container
Insert picture description here2. Go to the command vessel

docker exec -it [容器ID] /bin/bash

3. Enter the database account password command

mysql -uroot -p

4. Change the root password after entering the interface (123456 is my new password, the password here is up to you)

update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';

5. Refresh the cache

flush privileges;

6. Exit mysql

exit

7. Then re-enter mysql and log in with the modified password

Guess you like

Origin blog.csdn.net/y1534414425/article/details/108029737