Docker下简单使用MySQL
Docker下简单使用MySQL
Magnus马格纳斯 发表于3个月前
Docker下简单使用MySQL
  • 发表于 3个月前
  • 阅读 10
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

摘要: 简单配置主从复制
  • Docker安装
>curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

OK

>sudo add-apt-repository \

"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \

$(lsb_release -cs) \

stable"

>sudo apt-get install docker-ce

>sudo vi /etc/default/docker

DOCKER_OPTS="--registry-mirror=https://48h46wxj.mirror.aliyuncs.com"

>sudo usermod -aG docker username

>sudo service docker restart
  • MySQL镜像及容器创建

下载源GPG秘钥

>curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

>sudo docker pull mysql (Using default tag:latest )
  1. 启动第一个mysql服务
>sudo docker run -d -p 3307:3306 --name mysql3306 \

-v /opt/docker_v/mysql/3306/conf/3306.cnf:/etc/mysql/my.cnf \

-v /opt/docker_v/mysql/3306/data:/var/lib/mysql/data/3306 \

-v -e MYSQL_ROOT_PASSWORD=123456 \

mysql:latest

 

    2. 启动第二个mysql服务

>sudo docker run -d -p 127.0.0.1:3308:3306 --name mysql3307 \

-v /opt/docker_v/mysql/3307/conf/3306.cnf:/etc/mysql/my.cnf \

-v /opt/docker_v/mysql/3307/data:/var/lib/mysql \

-e MYSQL_ROOT_PASSWORD=123456 \

mysql:latest

 

    3. 宿主机访问Docker容器:

$ mysql -h127.0.0.1 -P3308 -uroot

 

    4. Docker MySQL 配置示例

# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.

#

# This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

▽ the Free Software Foundation; version 2 of the License.

#

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

# GNU General Public License for more details.

#

# You should have received a copy of the GNU General Public License

# along with this program; if not, write to the Free Software

# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA



#

# The MySQL Server configuration file.

#

# For explanations see

# http://dev.mysql.com/doc/mysql/en/server-system-variables.html



[mysqld]

pid-file = /var/run/mysqld/mysqld.pid

socket = /var/run/mysqld/mysqld.sock

datadir = /var/lib/mysql

#log-error = /var/log/mysql/error.log

# By default we only accept connections from localhost

#bind-address = 127.0.0.1

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

    5. MySQL 主从复制

mysql-master-server:

IP:172.17.0.2]

my.cnf

[mysqld]

... 其他配置

server-id=1

log-bin=mysql-bin #

mysql-slave-server:

IP:172.17.0.3

my.cnf

[mysqld]

... 其他配置

server-id=2

mysql> change master to master_host='172.17.0.2', master_user='root', master_password='123456';

mysql> start slave;

mysql> show slave status\G;

 

标签: Docker MySQL
共有 人打赏支持
粉丝 0
博文 13
码字总数 1527
×
Magnus马格纳斯
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: