一、实验目的:
mysql在主从复制还支持半同步复制,mysql复制是异步的,因为同步性能非常差。主库分发事件以后必须等待从库复制数据结束并收到从库正常响应以后,才能进行下一步操作。异步模式导致从库落后主库时,主库无从得知。因此mysql5.5后引入google补丁半同步复制,2个插件:semisync_master.so与semisync_slave.so。半同步:一主多从架构中,主库只等待一台从库复制完成数据并返回正常响应,就认为同步完成进行下一步操作,这样即有异步的高速,又有同步的安全。一旦主库等待从库响应超时,半同步复制自动降级为异步复制。半同步复制前提至少有一台从库与主库在同一机房,保证足够带宽,数据复制也足够快。因为对写性能影响极大又需要同步确认等待。
二、实验步骤
1.mysql支持的模块/插件
[root@master~]# ls -t /usr/local/mysql/lib/plugin/
debug semisync_slave.so mypluglib.so qa_auth_interface.so qa_auth_client.so adt_null.so daemon_example.ini semisync_master.so libdaemon_example.so qa_auth_server.so auth_test_plugin.so auth_socket.so auth.so
2.半同步模块安装
2.1主库
mysql>INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
mysql>SHOW GLOBAL VARIABLES LIKE '%semi%'; 服务器变量
+------------------------------------+-------+
|Variable_name |Value |
+------------------------------------+-------+
|rpl_semi_sync_master_enabled |OFF |
|rpl_semi_sync_master_timeout |10000 | 主从库连接超时过值,自动降为异步。毫秒
|rpl_semi_sync_master_trace_level |32 |
|rpl_semi_sync_master_wait_no_slave | ON | 没有从库也要等一下
+------------------------------------+-------+
mysql>SET GLOBAL rpl_semi_sync_master_enabled=1;
mysql>SET GLOBAL rpl_semi_sync_master_timeout=1000;
mysql>SHOW GLOBAL STATUS LIKE '%semi%';
+--------------------------------------------+-------+
|Variable_name | Value |
+--------------------------------------------+-------+
|Rpl_semi_sync_master_clients | 1 | 从节点1个
|Rpl_semi_sync_master_net_avg_wait_time | 0 |
|Rpl_semi_sync_master_net_wait_time | 0 |
|Rpl_semi_sync_master_net_waits | 0 |
|Rpl_semi_sync_master_no_times | 0 |
|Rpl_semi_sync_master_no_tx | 0 |
|Rpl_semi_sync_master_status | ON |
|Rpl_semi_sync_master_timefunc_failures | 0 |
|Rpl_semi_sync_master_tx_avg_wait_time | 0 |
|Rpl_semi_sync_master_tx_wait_time | 0 |
|Rpl_semi_sync_master_tx_waits | 0 |
|Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
|Rpl_semi_sync_master_wait_sessions | 0 |
|Rpl_semi_sync_master_yes_tx | 0 |
+--------------------------------------------+-------+
mysql>USE school;
mysql>CREATE TABLE tb2(name CHAR(20));
mysql>SHOW GLOBAL STATUS LIKE '%semi%';
+--------------------------------------------+-------+
|Variable_name | Value |
+--------------------------------------------+-------+
|Rpl_semi_sync_master_clients | 1 |
|Rpl_semi_sync_master_net_avg_wait_time | 800 | 等待从服返回报告时间
|Rpl_semi_sync_master_net_wait_time | 800 |
|Rpl_semi_sync_master_net_waits | 1 |
|Rpl_semi_sync_master_no_times | 0 |
|Rpl_semi_sync_master_no_tx | 0 |
|Rpl_semi_sync_master_status | ON |
|Rpl_semi_sync_master_timefunc_failures | 0 |
|Rpl_semi_sync_master_tx_avg_wait_time | 715 | 等待从服事务返回报告时间
|Rpl_semi_sync_master_tx_wait_time | 715 |
|Rpl_semi_sync_master_tx_waits | 1 |
|Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
|Rpl_semi_sync_master_wait_sessions | 0 |
|Rpl_semi_sync_master_yes_tx | 1 |
+--------------------------------------------+-------+
mysql>INSERT INTO tb2 VALUES ('tom'),('jerry'),('jack');
mysql>SHOW GLOBAL STATUS LIKE '%semi%';
+--------------------------------------------+-------+
|Variable_name | Value |
+--------------------------------------------+-------+
|Rpl_semi_sync_master_clients | 1 |
|Rpl_semi_sync_master_net_avg_wait_time | 1518 |
|Rpl_semi_sync_master_net_wait_time | 3037 |
|Rpl_semi_sync_master_net_waits | 2 |
|Rpl_semi_sync_master_no_times | 0 |
|Rpl_semi_sync_master_no_tx | 0 |
|Rpl_semi_sync_master_status | ON |
|Rpl_semi_sync_master_timefunc_failures | 0 |
|Rpl_semi_sync_master_tx_avg_wait_time | 715 |
|Rpl_semi_sync_master_tx_wait_time | 715 |
|Rpl_semi_sync_master_tx_waits | 1 |
|Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
|Rpl_semi_sync_master_wait_sessions | 0 |
|Rpl_semi_sync_master_yes_tx | 2 |
+--------------------------------------------+-------+
从库
mysql>INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
mysql>SHOW GLOBAL VARIABLES LIKE '%semi%';
+---------------------------------+-------+
|Variable_name | Value |
+---------------------------------+-------+
|rpl_semi_sync_slave_enabled |OFF |
|rpl_semi_sync_slave_trace_level | 32 |
+---------------------------------+-------+
mysql>SET GLOBAL rpl_semi_sync_slave_enabled=1;
mysql>STOP SLAVE;
mysql>START SLAVE;
mysql>SHOW GLOBAL STATUS LIKE '%semi%';
+----------------------------+-------+
|Variable_name | Value |
+----------------------------+-------+
|Rpl_semi_sync_slave_status | ON |
+----------------------------+-------+
永久配置在Master和Slave的my.cnf中编辑:
# OnMaster
[root@master~]# vim /etc/my.cnf
[mysqld]
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000# 1 second
验证
mysql>SHOW GLOBAL VARIABLES LIKE '%semi%';
+------------------------------------+-------+
|Variable_name | Value |
+------------------------------------+-------+
|rpl_semi_sync_master_enabled |ON |
|rpl_semi_sync_master_timeout |1000 |
|rpl_semi_sync_master_trace_level |32 |
|rpl_semi_sync_master_wait_no_slave | ON |
+------------------------------------+-------+
# OnSlave
[root@slave~]# vim /etc/my.cnf
[mysqld]
rpl_semi_sync_slave_enabled=1
验证
mysql>SHOW GLOBAL VARIABLES LIKE '%semi%';
+---------------------------------+-------+
|Variable_name | Value |
+---------------------------------+-------+
|rpl_semi_sync_slave_enabled | ON |
|rpl_semi_sync_slave_trace_level | 32 |
+---------------------------------+-------+

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version
Chinese version, very easy to use
