Mysql版本

通过docker启动的mysql容器

mysql版本

root@1651d1cab219:/# mysql --version
mysql Ver 14.14 Distrib 5.6.19-v1, for Linux (x86_64) using EditLine wrapper

配置Master

Master需要一个唯一性的服务器ID。

一个二进制文件记录数据的变动。

一个可以读取二进制文件的mysql账号。

打开mysql配置文件找到如下内容。

#server-id              = 1
log_bin = /etc/mysql/data/mysql-bin.log
expire_logs_days = 2
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name

最后把内容改成如下内容

server-id              = 1
log_bin = /etc/mysql/data/mysql-bin.log
log_bin_index = /etc/mysql/data/mysql-bin.index
expire_logs_days = 2
max_binlog_size = 100M
binlog_do_db = test
binlog_ignore_db = mysql

重启mysql 在宿主机器上重启该mysql容器

重新进入到容器

在mysql的test库中创建一张测试表

先查看master 二进制位置

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 | 121 | test | mysql | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec) mysql> reset master; mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 121 | test | mysql | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

说明master配置已经运行

创建 复制账号

GRANT REPLICATION SLAVE ON *.* TO 'repl_user'@'%' IDENTIFIED BY '';

已经不能在语句上赋值数据库名称了,如果需要过滤数据库需要配置文件的配置项

#binlog_do_db           = include_database_name
#binlog_ignore_db = include_database_name

分别表示需要记录的数据库和不需要记录的数据库选项。

配置Slave

在slave服务器mysql的配置文件中添加

server-id              = 2
relay_log_index = /etc/mysql/data/slave-relay-bin.index
relay_log = /etc/mysql/data/slave-relay-bin.log

重启docker容器

连接 Slave到Master

CHANGE MASTER TO MASTER_HOST='172.17.0.2',MASTER_PORT=3306,MASTER_USER = 'repl_user',MASTER_PASSWORD='';
START SLAVE;

Master服务器添加数据

mysql> use test;
Database changed mysql> CREATE TABLE `a` (
-> `id` int(11) NOT NULL AUTO_INCREMENT,
-> `name` varchar(16) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Query OK, 0 rows affected (0.11 sec) mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| a |
+----------------+
1 row in set (0.00 sec)

Slave查看同步结果与状态

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| a |
+----------------+
1 row in set (0.00 sec) mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.17.0.2
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 401
Relay_Log_File: slave-relay-bin.000002
Relay_Log_Pos: 565
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 401
Relay_Log_Space: 739
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 8bb5a52d-5fe2-11e6-841c-0242ac110002
Master_Info_File: /etc/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)

我们的基本的主从Mysql搭建已经完成。

配置Master与Slave实现主从同步的更多相关文章

  1. Redis单机配置多实例,实现主从同步

    版权声明:本文为博主原创文章,欢迎转载,转载请保留或注明出处 本文转自:http://www.cnblogs.com/lgeng/p/6623336.html 一,单机多实例:Redis官网: htt ...

  2. redis配置master-slave模式

    由于云服务器存在闪断现象,项目线上会存在基于redis的功能在闪断时段内出现异常,所以redis需要做master-slave模式.直接上代码: 原单机redis,RedisConnectionFac ...

  3. mysql数据库配置主从同步

    MySQL主从同步的作用 .可以作为一种备份机制,相当于热备份 .可以用来做读写分离,均衡数据库负载 MySQL主从同步的步骤 一.准备操作 .主从数据库版本一致,建议版本5.5以上 .主从数据库数据 ...

  4. mysql 主从 同步原理及配置

    一.在mssql 里头实现同步镜像,只能主库用而镜像库不能同时用,而mysql 主从同步可以实现 数据库的读写分离,主库负责 update insert delete ,从库负责select 这样一来 ...

  5. Mysql主从同步的实现原理与配置实战

    1.什么是mysql主从同步? 当master(主)库的数据发生变化的时候,变化会实时的同步到slave(从)库. 2.主从同步有什么好处? 水平扩展数据库的负载能力. 容错,高可用.Failover ...

  6. MySQL主从介绍、配置主从、测试主从同步

    6月28日任务 说明:有不少同学不能一次性把实验做成功,这是因为还不熟悉,建议至少做3遍17.1 MySQL主从介绍17.2 准备工作17.3 配置主17.4 配置从17.5 测试主从同步有的同学,遇 ...

  7. mysql数据库主从同步

    环境: Mater:   CentOS7.1  5.5.52-MariaDB  192.168.108.133 Slave:   CentOS7.1  5.5.52-MariaDB  192.168. ...

  8. MariaDB主从复制,redis发布订阅,持久化,以及主从同步

      一. MariaDB主从复制 mysql基本操作 1 连接数据库 mysql -u root -p -h 127.0.0.1 mysql -u root -p -h 192.168.12.60 2 ...

  9. Mysql主从同步(1) - 概念和原理介绍 以及 主从/主主模式 部署记录

    Mysql复制概念Mysql内建的复制功能是构建大型高性能应用程序的基础, 将Mysql数据分布到多个系统上,这种分布机制是通过将Mysql某一台主机数据复制到其它主机(slaves)上,并重新执行一 ...

随机推荐

  1. HDU 4259(Double Dealing-lcm(x1..xn)=lcm(x1,lcm(x2..xn))

    Double Dealing Time Limit: 50000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. Codeforces Round #277 (Div. 2)A. Calculating Function 水

    A. Calculating Function   For a positive integer n let's define a function f: f(n) =  - 1 + 2 - 3 +  ...

  3. ArcGis空间参考的设置

    ArcGis10.0空间参考设置: 选择一个数据右击,进入属性properties 点击进入后则出现以下界面 双击进入后则出现以下界面 双击进入后出现如下界面,此时则可选择需要设置的空间参考 ArcG ...

  4. What is the difference between task and thread?

    http://stackoverflow.com/questions/4130194/what-is-the-difference-between-task-and-thread 回答一: A tas ...

  5. B1391 [Ceoi2008]order 最大权闭合图 最小割

    啊啊啊,假的题吧!!!我用的当前弧优化T了6个点,其他人不用优化AC!!!震惊!!!当前弧优化是假的吧!!! 到现在我也没调出来...大家帮我看看为啥70.... 来讲一下这个题的思路,就是设一个源点 ...

  6. Section %post does not end with %end

    Section %post does not end with %end Exception AttributeError: "NoneType" object no attrib ...

  7. 插入1000万条数据到mysql数据库表

    转自:https://www.cnblogs.com/fanwencong/p/5765136.html 我用到的数据库为,mysql数据库5.7版本的 1.首先自己准备好数据库表 其实我在插入100 ...

  8. 洛谷P3047 [USACO12FEB]Nearby Cows(树形dp)

    P3047 [USACO12FEB]附近的牛Nearby Cows 题目描述 Farmer John has noticed that his cows often move between near ...

  9. 一、SQL系列之~使用SQL语言导出数据及实现定时导出数据任务

    一般情况下,SQL数据库中带有导入与导出数据的直接按键操作,点击数据表所在的数据库--任务--导出/导入数据,根据导入/导出向导直接将数据导出即可. 但导出的数据格式多为Excel格式,如果需要导出的 ...

  10. JNI学习积累之一 ---- 常用函数大全

    主要资料来源: 百度文库的<JNI常用函数> . 同时对其加以了补充 . 要素  :1. 该函数大全是基于C语言方式的,对于C++方式可以直接转换 ,例如,对于生成一个jstring类型的 ...