当前位置:网站首页>Docker installation MySQL simple without pit

Docker installation MySQL simple without pit

2022-06-24 23:00:00 Bald and weak.

List of articles

1. Switch root user

2. Download the image file

docker pull mysql:5.7

3. Create an instance and start

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

A long string of id It indicates that the mysql Successful launch

【 Port mapping and file mounting 】
Parameter description
-p 3306:3306: The container of 3306 Port mapping to host's 3306 port
-name: Container name
-v /mydata/mysql/conf:/etc/mysql: Mount the configuration folder to the host
-v /mydata/mysql/log:/var/log/mysql: Mount the log folder to the host
-v /mydata/mysql/data:/var/lib/mysql/: Mount the configuration folder to the host
-e MYSQL_ROOT_PASSWORD=root: initialization root User's password
-d It's backstage

Every docker It's all one linux System , So when starting the container, you need to set docker Is mapped to linux Host port
-v: take linux Local files and docker Specified file binding for , Modifying local files will synchronize docker file , It is much more convenient to modify the configuration

4.MySQL To configure
Due to the use -v /mydata/mysql/conf:/etc/mysql, Will local conf Directory and docker Configuration directory binding , It just needs to be modified linux Local configuration is enough .

vi /mydata/mysql/conf/my.cnf

[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 restart mysql
5. Tips : solve MySQL The problem of slow connection
Add the following... In the configuration file , And restart mysql

[mysqld]
skip-name-resolve

explain : skip-name-resolve: Skip domain name resolution

6. container-passing mysql Command line tool connection
docker exec -it mysql mysql -uroot -proot

7. Set up remote access
grant all privileges on . to ‘root’@‘%’ identified by ‘root’ with grant option; flush privileges;

8. use navicat Connect and have a look
Default root User password is root
 Insert picture description here

原网站

版权声明
本文为[Bald and weak.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241706052093.html