使用dockers安装MySQL
Posted 三度
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用dockers安装MySQL相关的知识,希望对你有一定的参考价值。
事前准备
- 关闭selinux
setenforce 0
vim /etc/sysconfig/selinux
SELINUX=disabled
# 若不关闭,使用docker启动mysql5.7镜像容器时启动不起来,查看日志会有如下错误显示:
ERROR: mysqld failed while attempting to check config
command was: "mysqld --verbose --help"
mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
ERROR: mysqld failed while attempting to check config
command was: "mysqld --verbose --help"
mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
- 安装并启动docker
yum install epel-release
yum -y install docker
systemctl start docker.service
- 创建目录
mkdir -p /datavol/mysql-200/{mysql,conf}
把该文件放到主库所在配置文件路径下:/datavol/mysql-200/conf
配置my.cnf
[client]
port = 3306
default-character-set = utf8mb4
[mysql]
port = 3306
default-character-set = utf8mb4
[mysqld]
##########################
# summary
##########################
#bind-address = 0.0.0.0
#port = 3306
#datadir=/datavol/mysql/data #数据存储目录
##########################
# log bin
##########################
server-id = 200 #必须唯一
log_bin = mysql-bin #开启及设置二进制日志文件名称
binlog_format = MIXED
sync_binlog = 1
expire_logs_days =7 #二进制日志自动删除/过期的天数。默认值为0,表示不自动删除。
#binlog_cache_size = 128m
#max_binlog_cache_size = 512m
#max_binlog_size = 256M
binlog-do-db = test #要同步的数据库
binlog-ignore-db = mysql #不需要同步的数据库
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
##########################
# character set
##########################
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
安装启动主库
[root@localhost ~]# docker run -d -p 4200:3306 --name=mysql-200 -v /datavol/mysql-200/conf:/etc/mysql/conf.d -v /datavol/mysql-200:/datavol/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
5691bac538e646db00273e3cad5b350dbe6cce0bd176346b7eefd9a6f9e3a9ad
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5691bac538e6 mysql:5.7 "docker-entrypoint..." 44 seconds ago Up 43 seconds 33060/tcp, 0.0.0.0:4200->3306/tcp mysql-200
[root@localhost ~]# docker exec -it mysql-200 /bin/bash
root@5691bac538e6:/# mysql -u root -p
Enter password:
以上是关于使用dockers安装MySQL的主要内容,如果未能解决你的问题,请参考以下文章
学姐今天竟然问我Linux中如何使用docker安装mysql
Docker删除报错:Error response from daemon: conflict: unable to delete 08b152afcfae (must be forced)(代码片段