docker pull mysql:5.7
5.7 is the version number. You can go to https://hub.docker.com/_/mysql?tab=tags website to check the mysql version you want to install;
docker run -p 3306:3306 --name mysql \ -v /mydata/mysql/log:/var/log/mysql \ -v /mydata/mysql/data:/var/lib/mysql \ -v /mydata/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.7
Command analysis:
docker run -p 3306:3306 -- name mysql: Create a docker container, name it mysql, map the Linux port 3306 to the 3306 port of the docker container; (the first 3306 is for Linux, the latter is for the docker container)
[ -v]: It means directory mounting. Linux cannot directly access the files in the docker container. You can use this command to map the files in the docker container to the Linux directory;
-v /mydata/mysql/ log:/var/log/mysql: Map the files in the /var/log/mysql directory in the docker container to the /mydata/mysql/log file in Linux;
-e MYSQL_ROOT_PASSWORD=root :-e sets the parameters of mysql, here is the password of the mysql root user;
-d mysql:5.7: Start mysql 5.7;
Okay, mysql has been installed and started ;
Add the following code to the my.cnf file:
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve
docker restart mysql
The above is the detailed content of How to install mysql in docker. For more information, please follow other related articles on the PHP Chinese website!