当前位置:网站首页>docker安装mysql5.7(仅供测试使用)
docker安装mysql5.7(仅供测试使用)
2022-08-11 05:36:00 【MssGuo】
前言
环境:Centos7.9 mysql5.7 Docker version 20.10.9
mysql数据库建议使用物理机安装,这里使用docker安装mysql仅供测试使用或其他不重要场景使用。
docker 安装mysql5.7
#创建mysql的文件存放目录
[[email protected] ~]# mkdir -p /usr/local/mysql/conf
[[email protected] ~]# mkdir -p /usr/local/mysql/logs
[[email protected] ~]# mkdir -p /usr/local/mysql/mysql
[[email protected] ~]# cd /usr/local/mysql/conf
[[email protected] conf]# vim my.cnf #创建mysql配置文件
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
default-time_zone = '+8:00' #默认时区配置
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION #设置数据库支持分组
lower_case_table_names=1
#启动mysql5.7容器,并使用-v参数持久化存储mysql的数据
[[email protected] ~]# docker run --restart always -p 3306:3306 --name mysql5.7 -v /usr/local/mysql/conf/:/etc/mysql/ -v /usr/local/mysql/logs:/var/log/mysql -v /usr/local/mysql/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
#查看mysql5.7容器,已经启动了
[[email protected] mysql]# docker ps | grep mysql5.7
1019a1f67f2d mysql:5.7 "docker-entrypoint.s…" 30 minutes ago Up 30 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql5.7
[[email protected] mysql]#
#进入容器查看mysql容器是否可用
[[email protected] ~]# docker exec -it mysql5.7 bash #进入容器
[email protected]:/# mysql -uroot -p123456 #登录mysql
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; #执行命令,一切正常,说明MySQL可用
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql>
备注:因为我们在启动mysql5.7容器的时候做了主机端口映射,所以外部应用程序直接链接主机ip:3306即可使用容器的mysql数据库。
边栏推荐
- 损失函数——负对数似然
- Taobao API interface reference
- Open Set Domain Adaptation 开集领域适应
- sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
- The ramdisk practice 1: the root file system integrated into the kernel
- 训练分类器
- 已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
- Xshell如何连接虚拟机
- 实现通用的、高性能排序和快排优化
- 强烈推荐一款好用的API接口
猜你喜欢
随机推荐
图的拉普拉斯矩阵
Implement general-purpose, high-performance sorting and quicksort optimizations
每日sql-统计各个专业人数(包括专业人数为0的)
SATA、SAS、SSD三种硬盘存储性能数据
arcgis填坑_4
torch.cat()用法
求过去半年内连续30天以上每天都有1000元以上成交的商铺
每日sql - 判断+聚合
HCIP-BGP的选路实验
iptables的状态
【预约观看】Ambire 智能钱包 AMA 活动第四期即将举行
MySQL01
MySQL导入导出&视图&索引&执行计划
arcgis填坑_1
redis + lua实现分布式接口限流实现方案
抖音API接口
HCIP OSPF dynamic routing protocol
拼多多api接口应用示例
Daily sql - judgment + aggregation
WiFi Deauth 攻击演示分析 // mdk4 // aireplay-ng// Kali // wireshark //