当前位置:网站首页>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
边栏推荐
猜你喜欢
After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items
sar命令详解
Pass in external parameters to the main function in clion
Tongxin UOS php7 2.3 upgrade to php7.0 two point two four
TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别
API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
HyperBDR云容灾V3.3.0版本发布|容灾功能升级,资源组管理功能优化
困扰多年的系统调研问题有自动化采集工具了,还是开源免费的
教育行业云迁移最佳实践:海云捷迅使用HyperMotion云迁移产品为北京某大学实施渐进式迁移,成功率100%
MySQL-InnoDB-事务
随机推荐
Recyclerview advanced use (II) - simple implementation of vertical drag and drop sorting
多云数据流转?云上容灾?年前最后的价值内容分享
01-nio basic ByteBuffer and filechannel
Installation and use of postman pit
Operation instructions of star boundary automatic text translator (advanced version)
Pass in external parameters to the main function in clion
DP energy Necklace
使用Executors类快速创建线程池
std::map 和 std::vector 内存释放
第四届“传智杯”全国大学生IT技能大赛(决赛B组) 题解
About the configuration and use of json5 in nodejs
Storage path of mod subscribed by starbound Creative Workshop at Star boundary
JS recursion (1)
JS format time
时间复杂度计算举例
HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
MySQL数据库讲解(九)
Research on recyclerview details - Discussion and repair of recyclerview click dislocation
编译Openssl
一些小小小小记录~