Home > Database > Mysql Tutorial > How to install mysql in docker

How to install mysql in docker

王林
Release: 2023-05-27 18:52:06
forward
7647 people have browsed it

1. Use the docker command to download mysql

docker pull mysql:5.7
Copy after login

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;

How to install mysql in docker

2. Use the docker command to create an instance and start it;

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
Copy after login

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 ;

How to install mysql in docker

3. Modify the mysql configuration file;

How to install mysql in docker

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
Copy after login

4. Restart mysql;

docker restart mysql
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template