当前位置:网站首页>Docker (V) MySQL installation
Docker (V) MySQL installation
2022-04-23 14:19:00 【anron】
One 、MySQL 8.0 Installation
1.1 Pull the mirror image
docker pull mysql:latest
The mirror is MySQL 8.0.20 Community Server - GPL
1.2 Create a container
docker run -d --restart=always --name mysql \
-v /etc/localtime:/etc/localtime:ro \
-v /ljh/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 3306:3306 \
mysql:latest --lower_case_table_names=1
Be careful : --lower_case_table_names=1 To be added after the image name , Otherwise, it will report a mistake ,MySQL8 The version can only configure whether the table name is case sensitive during initialization , This parameter cannot be modified after initialization
MYSQL_ROOT_PASSWORD Parameter assignment MySQL The password for 123456
/etc/localtime Set the time zone in the container to be consistent with the host
1.3 modify root Password of account
docker exec -it mysql /bin/bash
mysql -uroot -p123456
mysql> use mysql;
mysql> show variables like 'lower_case_table_names';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_table_names | 1 |
+------------------------+-------+
1 row in set (0.00 sec)
mysql> select host, user, plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)
mysql> alter user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '654321';
Query OK, 0 rows affected (0.00 sec)
mysql> select host, user, plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)
In this way, the database is logged in locally (host=localhost) The password for is 123456, Remote login (host=%) The password for is 654321
Be careful :MySQL 8.0 The default is caching_sha2_password encryption ,MySQL 5.X yes mysql_native_password
1.4 To configure my.cnf
This is a revision my.cnf Previous configuration
mysql> show variables like 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
1 row in set (0.00 sec)
# Copy out the... In the container first my.cnf file
docker cp mysql:/etc/mysql/my.cnf /ljh/mysql/my.cnf
# Modify the copied file , stay [mysqld] Add configuration under
[mysqld]
default_authentication_plugin=mysql_native_password
# Copy the modified file into the container
docker cp /ljh/mysql/my.cnf mysql:/etc/mysql/my.cnf
# Restart container
docker restart mysql
mysql> show variables like 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| default_authentication_plugin | mysql_native_password |
+-------------------------------+-----------------------+
1 row in set (0.00 sec)
1.5 Change the time zone
If it doesn't work 【-v /etc/localtime:/etc/localtime:ro】 Created container , There will be time zone inconsistencies , It needs to be modified manually .Mysql The default image is UTC The time zone ,SQL Statement now() Got it later than Beijing time 8 Hours , You need to enter the image and adjust the time zone to CST
[root@localhost ~]# mv /etc/localtime /etc/localtime.bak
[root@localhost ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Two 、MySQL 5.7 Installation
2.1 Pull the mirror image
docker pull mysql:5.7
2.2 Create a container
docker run -d --restart=always --name mysql \
-v /etc/localtime:/etc/localtime:ro \
-v /ljh/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 3306:3306 \
mysql:5.7
2.3 modify root Password of account
and 1.3 In the same
2.4 To configure mysqld.cnf
# Copy out the... In the container first mysqld.cnf file
docker cp mysql:/etc/mysql/mysql.conf.d/mysqld.cnf /ljh/mysql/mysqld.cnf
# Modify the copied file , stay [mysqld] Add configuration under
[mysqld]
lower_case_table_names=1
# Copy the modified file into the container
docker cp /ljh/mysql/mysqld.cnf mysql:/etc/mysql/mysql.conf.d/mysqld.cnf
# Restart container
docker restart mysql
3、 ... and 、Docker-compose Lower installation
3.1 docker-compose.yml The documents are as follows
version: "3"
networks:
anron-net:
driver: bridge
services:
anron-database-1:
image: mysql:5.7
container_name: mysql5.7
restart: always
networks:
- anron-net
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
command:
--lower_case_table_names=1
volumes:
- /ljh/mysql5.7/data:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
anron-database-2:
image: mysql:latest
container_name: mysql8.0
restart: always
networks:
- anron-net
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
command:
--default-authentication-plugin=mysql_native_password
--lower_case_table_names=1
volumes:
- /ljh/mysql8.0/data:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
版权声明
本文为[anron]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231409381078.html
边栏推荐
- API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
- Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
- Flop effect
- HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
- 云迁移的六大场景
- API Gateway/API 网关(三) - Kong的使用 - 限流rate limiting(redis)
- Use the executors class to quickly create a thread pool
- MySQL数据库讲解(八)
- 返回数组排序后下标
- API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件
猜你喜欢
微信小程序客服接入,实现发送和接收消息
HyperBDR云容灾V3.3.0版本发布|容灾功能升级,资源组管理功能优化
常见存储类型和FTP主被动模式解析
Win10 comes with groove music, which can't play cue and ape files. It's a curvilinear way to save the country. It creates its own aimpack plug-in package, and aimp installs DSP plug-in
MySQL数据库讲解(九)
剑指offer刷题(2)--面向华为
HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
微信小程序将原生请求通过es6的promise来进行优化
利用json-server在本地创建服务器请求
MySQL数据库讲解(八)
随机推荐
Web page, adaptive, proportional scaling
How to do a project easily
x509证书cer格式转pem格式
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
Returns the subscript after array sorting
贷款市场报价利率(LPR)与贷款基准利率介绍
MySQL同步Could not find first log file name in binary log index file错误
关于UDP接收icmp端口不可达(port unreachable)
关于云容灾,你需要知道这些
JS format time
云容灾是什么意思?云容灾和传统容灾的区别?
正则表达式
MySQL数据库讲解(七)
js 递归(1)
redis数据库讲解(三)redis数据类型
Notes on Visio drawing topology
Nacos作为配置中心(四) 使用Demo
HyperBDR云容灾V3.3.0版本发布|容灾功能升级,资源组管理功能优化
网页自适应,等比缩放
Date的after时间判断