mysql主从之双主配置
mysql双主配置
mysql双主其实就是互相同步,互为主从
任意一台都能够执行插入动作
生产环境用得非常少,因为还是担心数据一致的问题
生产环境一般来说主从已经够用
172.19.132.121的配置,自增的话从1开始,每次递增2.数值是1,3,5,7……
[mysqld]
bind-address=0.0.0.0
port=
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=
innodb_flush_log_at_trx_commit =
log_warnings =
connect_timeout =
net_read_timeout =
performance_schema_max_table_instances =
server-id =
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format = ROW
auto_increment_offset=
auto_increment_increment= [mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid
192.168.132.122的配置,自增的话从2开始,每次递增2,数值是2,4,6,8……
[mysqld]
bind-address=0.0.0.0
port=
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=
innodb_flush_log_at_trx_commit =
log_warnings =
connect_timeout =
net_read_timeout =
performance_schema_max_table_instances =
server-id =
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format = ROW
auto_increment_offset=
auto_increment_increment= [mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid
防止索引一致,导致插入失败
重启数据库
先赋予对应的权限
192.168.132.121配置
mysql> grant replication slave on *.* to 'replication'@'192.168.132.122' identified by '1234567';
192.168.132.122配置
mysql> grant replication slave on *.* to 'replication'@'192.168.132.121' identified by '1234567';
启动互相同步
192.168.121操作
mysql> change master to master_host='192.168.132.122',master_port=,master_user='replication',master_password='',master_log_file='master-bin.000001',master_log_pos=;
Query OK, rows affected, warnings (0.01 sec) mysql> start slave;
Query OK, rows affected (0.00 sec) mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.122
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 141defd2-9dab-11e9-8fe3-000c2963fd11
Master_Info_File: /data/mysql/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec) ERROR:
No query specified mysql> show mater logs;
ERROR (): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mater logs' at line
mysql> show master logs;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-bin. | |
+-------------------+-----------+
192.168.132.122操作
mysql> change master to master_host='192.168.132.121',master_port=,master_user='replication',master_password='',master_log_file='master-bin.000001',master_log_pos=;
Query OK, rows affected, warnings (0.01 sec) mysql> start slave;
Query OK, rows affected (0.00 sec) mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.121
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 77278e78-9da8-11e9-bc6c-000c2991dd19
Master_Info_File: /data/mysql/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)
查看进程
mysql> mysql> show processlist;
验证双主状态
.121创建数据库
mysql> create database darren;
Query OK, row affected (0.00 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| darren |
| mysql |
| performance_schema |
| sys |
+--------------------+
.122查看并创建数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| darren |
| mysql |
| performance_schema |
| sys |
+--------------------+
mysql> create database darren1;
Query OK, row affected (0.00 sec)
.121查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| darren |
| darren1 |
| mysql |
| performance_schema |
| sys |
+--------------------+
其他指令比较
.121操作
mysql> use darren;
Database changed
mysql> create table test( id int primary key NOT NULL auto_increment, name varchar() );
Query OK, rows affected (0.01 sec) mysql> show master logs;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-bin. | |
+-------------------+-----------+
row in set (0.00 sec)
.122插入一个数据
mysql> use darren;
Database changed
mysql> insert into test values (null, 'shijiange');
Query OK, row affected (0.00 sec)
.121查看
mysql> show binlog events in 'master-bin.000001'; #同步的数据没有记录到日志中来
+-------------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------------------------------------+
| master-bin. | | Format_desc | | | Server ver: 5.7.-log, Binlog ver: |
| master-bin. | | Previous_gtids | | | |
| master-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| master-bin. | | Query | | | create database darren |
| master-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| master-bin. | | Query | | | use `darren`; create table test( id int primary key NOT NULL auto_increment, name varchar() ) |
+-------------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------------------------------------+
mysql> select * from test;
+----+-----------+
| id | name |
+----+-----------+
| | shijiange | #是以2开始,每次加2
+----+-----------+
同时插入一条数据
mysql> insert into test values (null, UUID());
Query OK, row affected (0.01 sec) mysql> select * from test;
+----+--------------------------------------+
| id | name |
+----+--------------------------------------+
| | shijiange |
| | eb11d3b8-9e7d-11e9--000c2991dd19 | #以奇数开始,每次加2
+----+--------------------------------------+
mysql> insert into test values (null, UUID());
Query OK, row affected (0.01 sec) mysql> select * from test;
+----+--------------------------------------+
| id | name |
+----+--------------------------------------+
| | shijiange |
| | eb11d3b8-9e7d-11e9--000c2991dd19 |
| | f331ca26-9e7d-11e9--000c2991dd19 |
+----+--------------------------------------+
.122插入数据
mysql> insert into test values (null, UUID());
Query OK, row affected (0.01 sec) mysql> select * from test;
+----+--------------------------------------+
| id | name |
+----+--------------------------------------+
| | shijiange |
| | eb11d3b8-9e7d-11e9--000c2991dd19 |
| | f331ca26-9e7d-11e9--000c2991dd19 |
| | f8ca41f9-9e7d-11e9-ba37-000c2963fd11 |
+----+--------------------------------------+
rows in set (0.00 sec) mysql> insert into test values (null, UUID());
Query OK, row affected (0.00 sec) mysql> select * from test;
+----+--------------------------------------+
| id | name |
+----+--------------------------------------+
| | shijiange |
| | eb11d3b8-9e7d-11e9--000c2991dd19 |
| | f331ca26-9e7d-11e9--000c2991dd19 |
| | f8ca41f9-9e7d-11e9-ba37-000c2963fd11 |
| | 043f7a3f-9e7e-11e9-ba37-000c2963fd11 |
+----+--------------------------------------+
.121插入数据
双主配置完成
mysql主从之双主配置的更多相关文章
- MySQL Replication, 主从和双主配置
MySQL Replication, 主从和双主配置 MySQL的Replication是一种多个MySQL的数据库做主从同步的方案,特点是异步,广泛用在各种对MySQL有更高性能,更高可靠性要求的场 ...
- keepalived主从及双主配置
高可用有2中方式. 1.Nginx+keepalived 主从配置 这种方案,使用一个vip地址,前端使用2台机器,一台做主,一台做备,但同时只有一台机器工作,另一台备份机器在主机器不出现故障的时候, ...
- mysql 主从,双主同步
1.创建用户并设置远程访问授权 1). A上添加: //ip地址为B的ip地址,用于B访问 ' with grant option; 2). B上添加://ip地址为A的ip地址,用于A访问 ' wi ...
- MySQL复制:主从和双主配置
对比Replication和Cluster 应用层中间件的负载均衡 异步的复制过程 MySQL官方使用Replication场景
- MYSQL 双主配置
MYSQL1. 版本号:5.7.243. 部署方式:双主部署,两台机器即是主又是备 ,双向拷贝,可以同时写入.4. 安装部署路径: a) /home/softb) 配置路径 /etc/my.cnfc) ...
- MySQL双主配置
MySQL双主配置 准备环境:服务器操作系统为RHEL6.4 x86_64,为最小化安装.主机A和主机B均关闭防火墙和SELINUX ,IP地址分别为192.168.131.129和192.168.1 ...
- ssdb主从及双主模型配置和简单管理
ssdb主从及双主模型配置和简单管理 levelDB是一个key->value 的数据存储库,其只能在本地保存数据,支持持久化,并且支持保存非常大的数据,单机redis在保存较大数据的时候数十G ...
- MySQL的双主配置
配置MySQL双主配置,需要先配置MySQL的主从复制,传送门: 0.集群规划 hadoop105 hadoop106 hadoop107 MySQL(master,slave) MySQL(slav ...
- centos 下 mysql+keepalived实现双主自由切换
目录 ip规划 mysql双主配置 keepalived配置 mysql1中keepalived的配置 mysql2中keepalived的配置 VIP漂移检测 本文的目的是搭建一个互为主从的mysq ...
随机推荐
- hdu 1025 lis 注意细节!!!【dp】
感觉这道题浪费了我半个小时的生命......哇靠!原来输出里面当len=1时是road否则是roads!!! 其实做过hdu 1950就会发现这俩其实一样,就是求最长上升子序列.我用结构体记录要连线的 ...
- UVa 10599【lis dp,记忆化搜索】
UVa 10599 题意: 给出r*c的网格,其中有些格子里面有垃圾,机器人从左上角移动到右下角,只能向右或向下移动.问机器人能清扫最多多少个含有垃圾的格子,有多少中方案,输出其中一种方案的格子编号. ...
- Visual Studio中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法
解决方案:选中项目中引入的dll,鼠标右键,选择属性,把“嵌入互操作类型”设置为False,问题轻松解决. 问题分析: 1.”嵌入互操作类型”中的嵌入就是引进.导入的意思,类似于c#中using,c中 ...
- Git 的两种忽略文件方式 gitignore 和 exclude
Git 的两种忽略文件方式 gitignore 和 exclude .gitignore 不用说了,大家都知道. 有一个 exclude 可能接触比较少. 知道这个功能后发现,用在服务器上非常方便,因 ...
- jenkins集成错误 标签: 发布 2016-01-10 20:45 747人阅读 评论(21) 收藏
进入ITOO的项目以后,终于要将自己负责的模块在jenkins上面集成发布了.首先自己按照文档要求一步一步的将配置完成,然后构建,不错所料出错了,经过修改,终于构建成功!构建成功以后就没再管了,结果第 ...
- 阿里云IPv6 DDoS防御被工信部认定为“网络安全技术应用试点示范项目”
近日,阿里云数据中心骨干网IPv6 DDoS网络安全防御被工业和信息化部认定为“网络安全技术应用试点示范项目”,本次评选由工业和信息部网络安全管理局发起,从实用性.创新性.先进性.可推广性等维度展 ...
- JVM 调优 —— GC 长时间停顿问题及解决方法
零. 简介 垃圾收集器长时间停顿,表现在 Web 页面上可能是页面响应码 500 之类的服务器错误问题,如果是个支付过程可能会导致支付失败,将造成公司的直接经济损失,程序员要尽量避免或者说减少此类情况 ...
- PHP怎么调用其他类的方法
2个PHP,这个PHP中的类调用另一个PHP中的类,如何调用.Java中是import ,php中是什么?还是用其他什么方法? 1.引用类:比如类名为product,则:include('...路径/ ...
- 图表echarts折线图,柱状图,饼状图
总体就是有折线图相关图标的设置,x,y轴的设置,x,y轴或者数据加上单位的设置.饼状图如何默认显示几个数据中的某个数据 折线图:legend(小标题)中间默认是圆圈 改变成直线 在legend设置的时 ...
- jquery实用应用之jquery操作radio、checkbox、select
本文收集一些jquery的实用技巧,非常实用的哦,其中对radio.checkbox.select选中与取值的方法. 获取一组radio被选中项的值var item = $('input[@name= ...