Use the command to pull mysql. The last version currently is 8.0.2*
docker pull mysql
It can also be viewed on dockerhub Download the specified version.
docker run --name mysql01 -p 3333:3306 -e MYSQL_ROOT_PASSWORD=123654 mysql:latest docker ps //查看运行的容器 docker exec -it mysql01 /bin/bash //进入控制台
Start mysql:
-it:-i->In interactive mode Run the container, -t-> reassign a pseudo input terminal to the container. Generally, these two are used together.
-p 3333:3306 The default 3306 is not used. It is changed to the mysql3306
–name bit of the host's 3333 mapping container. To give a name to the container, you need mysql01
-e to configure the application in the container. A password is set here
/bin/bash after startup Enter the console of the container
mysql -u root -p //然后输入密码
status;
GRANT ALL ON *.* TO 'root'@'%';//远程连接 flush privileges; //刷新权限 ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;//更改加密规则 ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123654';//设置密码 flush privileges;//刷新权限
The above is the detailed content of How to install MySql8 with Docker and access it remotely. For more information, please follow other related articles on the PHP Chinese website!