Dokcer download and container change mysql password
The docker container downloads the mysql service (mysql:5.7)
-
docker pulls mysql:5.7 image
docker pull mysql:5.7
-
Check if the image is pulled successfully
docker images //View all images
docker image ls
-
start mysql:5.7
docker run -d --name mysql -v ~/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=diqiu -p 3306:3306 mysql:5.7
Note: diqiu is the password
-
Enter the mysql container
docker exec -ti mysql bash
-
open remote link
//login to mysql
mysql -uroot -pdiqiu
//Open remote connection
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘diqiu’ WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT; -
Restart the mysql service
docker restart mysql
change mysql password
-
Query docker container service
docker ps
-
Enter the mysql service
docker exec -ti mysql bash
-
log in to mysql
mysql -uroot -pdiqiu
-
change mysql password
set password for 'root' = password('new password');
-
Modify the local mysql password (otherwise the client tool cannot be used to connect)
set password for 'root'@'localhost'=password('new password');