当前位置:网站首页>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
边栏推荐
- xx项目架构随记
- API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
- 网页自适应,等比缩放
- redis数据库讲解二(redis高可用、持久化、性能管理)
- 微信小程序轮播图swiper
- HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
- API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件
- Get the thread return value. Introduction to the use of future interface and futuretask class
- 线程间控制之CountDownLatch和CyclicBarrier使用介绍
- redis数据库讲解(三)redis数据类型
猜你喜欢
随机推荐
API Gateway/API 网关(三) - Kong的使用 - 限流rate limiting(redis)
js 抛物线运动方法封装
倒计时1天~2022云容灾产品线上发布会即将开始
容灾有疑问?点这里
什么是云迁移?云迁移的四种模式分别是?
uni-app消息推送
Research on recyclerview details - Discussion and repair of recyclerview click dislocation
setcontext getcontext makecontext swapcontext
获取线程返回值Future接口与FutureTask类使用介绍
Flop effect
时间复杂度计算举例
On the problem of cliff growth of loss function in the process of training
openstack理论知识
处理 mkdir:无法创建目录“aaa“:只读文件系统
进入新公司,运维工程师从下面这几项了解系统的部署
IE8 browser prompts whether to block access to JS script
微信小程序将原生请求通过es6的promise来进行优化
错误:无法远程查找到密钥 “428F7ECC7117F726“
MySQL lock database lock
常见存储类型和FTP主被动模式解析