码迷,mamicode.com
首页 > 数据库 > 详细

使用dockers安装MySQL

时间:2019-10-09 10:57:29      阅读:557      评论:0      收藏:0      [点我收藏+]

标签:bash   image   isa   mkdir   failed   目录   pass   查看   启动mysql   

事前准备

  1. 关闭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!
  1. 安装并启动docker
yum install epel-release
yum -y install docker
systemctl start docker.service
  1. 创建目录
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

标签:bash   image   isa   mkdir   failed   目录   pass   查看   启动mysql   

原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/11640365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!