博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Docker下简单使用MySQL
阅读量:6076 次
发布时间:2019-06-20

本文共 2613 字,大约阅读时间需要 8 分钟。

hot3.png

  • 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/dockerDOCKER_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 modifyit 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.pidsocket = /var/run/mysqld/mysqld.sockdatadir = /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 riskssymbolic-links=0

 

    5. MySQL 主从复制

mysql-master-server:IP:172.17.0.2]my.cnf[mysqld]... 其他配置server-id=1log-bin=mysql-bin #mysql-slave-server:IP:172.17.0.3my.cnf[mysqld]... 其他配置server-id=2mysql> change master to master_host='172.17.0.2', master_user='root', master_password='123456';mysql> start slave;mysql> show slave status\G;

 

转载于:https://my.oschina.net/u/552906/blog/1554433

你可能感兴趣的文章
Q85 最大矩形
查看>>
【android】使用handler更新UI
查看>>
mochiweb 源码阅读(十五)
查看>>
前端面试中的常见的算法问题
查看>>
计算机语言的基本理论
查看>>
nodejs流之行读取器例子
查看>>
11本Java好书
查看>>
批量文件重命名工具
查看>>
为什么选用 React 创建混合型移动应用?
查看>>
支付宝app支付
查看>>
GitHub又受攻击了
查看>>
flask权限管理
查看>>
Meteor全栈开发平台 - 不仅仅是前端
查看>>
苹果移除openssl头文件
查看>>
前端碎片知识储备
查看>>
Redisson 成为 GitHub 里星星最多的 Redis Java 客户端
查看>>
C缺陷与陷阱(C Traps and Pitfalls)学习笔记
查看>>
strtr+array_combine实现简单的敏感词过滤
查看>>
域名注册商 GoDaddy 被指悄悄在托管网站页面植入脚本
查看>>
微服务架构 - 巧妙获取被墙的Docker镜像
查看>>