日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql数据库group_key_【MySQL】数据库复制:组复制(Group Replication)

發布時間:2024/9/27 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql数据库group_key_【MySQL】数据库复制:组复制(Group Replication) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

[root@wallet01?~]#?uuidgen

8d1945a5-5c74-4ba0-8240-e9d731110753

[root@wallet01?~]#?vi?/etc/my.cnf

##單主模型參數

[mysqld]

server-id?=?1

gtid_mode?=?on

enforce_gtid_consistency?=?on

log_bin?=?mysql-bin

binlog_format?=?row

binlog_checksum?=?none

binlog_cache_size?=?16M

max_binlog_cache_size?=?4G

max_binlog_size?=?128M

expire_logs_days?=?7

relay_log?=?relay-bin

master_info_repository?=?table

relay_log_info_repository?=?table

log_slave_updates?=?on

slave_parallel_type?=?LOGICAL_CLOCK

slave_parallel_workers?=?4

slave_preserve_commit_order?=?1

plugin_load_add='group_replication.so'

transaction_write_set_extraction?=?XXHASH64

group_replication_group_name?=?"8d1945a5-5c74-4ba0-8240-e9d731110753"

group_replication_start_on_boot?=?off

group_replication_member_weight?=?40

group_replication_local_address?=?"192.168.1.201:20001"

group_replication_group_seeds="192.168.1.201:20001,192.168.1.202:20001,192.168.1.203:20001"

[root@wallet01?~]#?vi?/etc/my.cnf

##多主模型參數

[mysqld]

group_replication_enforce_update_everywhere_checks?=?on

group_replication_single_primary_mode?=?off

[root@wallet01?~]#?mysql?-uroot?-pabcd@2019

mysql>?grant?replication?slave?on?*.*?to?'repl'@'192.168.1.%'?identified?by?'repl@2019';

Query?OK,?0?rows?affected,?1?warning?(0.02?sec)

mysql>?flush?privileges;

Query?OK,?0?rows?affected?(0.03?sec)

mysql>?reset?master;

Query?OK,?0?rows?affected?(0.10?sec)

mysql>?change?master?to?master_user='repl',master_password='repl@2019'?for?channel?'group_replication_recovery';

Query?OK,?0?rows?affected,?2?warnings?(0.25?sec)

mysql>?set?@@global.group_replication_bootstrap_group=on;

Query?OK,?0?rows?affected?(0.00?sec)

mysql>?start?group_replication;

Query?OK,?0?rows?affected?(2.46?sec)

mysql>?set?@@global.group_replication_bootstrap_group=off;

Query?OK,?0?rows?affected?(0.00?sec)

mysql>?select?*?from?performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------+-------------+--------------+

|?CHANNEL_NAME??????????????|?MEMBER_ID????????????????????????????|?MEMBER_HOST?|?MEMBER_PORT?|?MEMBER_STATE?|

+---------------------------+--------------------------------------+-------------+-------------+--------------+

|?group_replication_applier?|?d386a328-5494-11eb-8ff3-000c29f06629?|?wallet01????|????????3306?|?ONLINE???????|

+---------------------------+--------------------------------------+-------------+-------------+--------------+

1?row?in?set?(0.00?sec)

mysql>??create?user?xtrabackup@'localhost'?identified?by?'xtrabackup@2019';

Query?OK,?0?rows?affected?(0.07?sec)

mysql>?grant?reload,lock?tables,replication?client,process?on?*.*?to?xtrabackup@'localhost';

Query?OK,?0?rows?affected?(0.02?sec)

mysql>?flush?privileges;

Query?OK,?0?rows?affected?(0.03?sec)

[root@wallet01?~]#?su?-?mysql

[mysql@wallet01?~]$?ssh-keygen

[mysql@wallet01?~]$?ssh-copy-id?-i?~/.ssh/id_rsa.pub?mysql@wallet02

[mysql@wallet01?~]$?ssh-copy-id?-i?~/.ssh/id_rsa.pub?mysql@wallet03

[mysql@wallet01?~]$?ssh?wallet02?date

Mon?Feb?18?10:41:16?CST?2019

[mysql@wallet01?~]$?ssh?wallet03?date

Mon?Feb?18?10:42:30?CST?2019

[mysql@wallet01?~]$?xtrabackup?--backup?--user=xtrabackup?--password=xtrabackup@2019?--stream=tar?|?ssh?mysql@wallet02?\?"gzip?>/home/mysql/backup/`date?'+%Y-%m-%d_%H-%M-%S'`.tar.gz"

[mysql@wallet01?~]$?xtrabackup?--backup?--user=xtrabackup?--password=xtrabackup@2019?--stream=tar?|?ssh?mysql@wallet03?\?"gzip?>/home/mysql/backup/`date?'+%Y-%m-%d_%H-%M-%S'`.tar.gz"

[root@wallet02?~]#?vi?/etc/my.cnf

[mysqld]

server-id?=?2

gtid_mode?=?on

enforce_gtid_consistency?=?on

log_bin?=?mysql-bin

binlog_format?=?row

binlog_checksum?=?none

binlog_cache_size?=?16M

max_binlog_cache_size?=?4G

max_binlog_size?=?128M

expire_logs_days?=?7

relay_log?=?relay-bin

master_info_repository?=?table

relay_log_info_repository?=?table

log_slave_updates?=?on

slave_parallel_type?=?LOGICAL_CLOCK

slave_parallel_workers?=?4

slave_preserve_commit_order?=?1

plugin_load_add='group_replication.so'

transaction_write_set_extraction?=?XXHASH64

group_replication_group_name?=?"8d1945a5-5c74-4ba0-8240-e9d731110753"

group_replication_start_on_boot?=?off

group_replication_member_weight?=?30

group_replication_local_address?=?"192.168.1.202:20001"

group_replication_group_seeds="192.168.1.201:20001,192.168.1.202:20001,192.168.1.203:20001"

[root@wallet02?~]#?su?-?mysql

[mysql@wallet02?~]$?cd?backup

[mysql@wallet02?backup]$?tar?izxvf?2019-08-22_10-48-1.tar.gz

[mysql@wallet02?backup]$?xtrabackup?--prepare?--target-dir=/home/mysql/backup

[mysql@wallet02?backup]$?xtrabackup?--copy-back?--target-dir=/home/mysql/backup

[mysql@wallet02?backup]$?cat?xtrabackup_binlog_info

mysql-bin.000001????????50522845????????8d1945a5-5c74-4ba0-8240-e9d731110753:1-10758

[root@wallet02?~]#?service?mysqld?start

Logging?to?'/var/lib/mysql/wallet02.err'.

Starting?mysqld:???????????????????????????????????????????[??OK??]

[root@wallet02?~]#?mysql?-uroot?-pabcd@2019

mysql>?set?global?gtid_purged='8d1945a5-5c74-4ba0-8240-e9d731110753:1-10758';

Query?OK,?0?rows?affected?(0.02?sec)

mysql>?change?master?to?master_user='repl',master_password='repl@2019'?for?channel?'group_replication_recovery';

Query?OK,?0?rows?affected,?2?warnings?(0.11?sec)

mysql>?start?group_replication;

Query?OK,?0?rows?affected?(5.91?sec)

mysql>?select?*?from?performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------+-------------+--------------+

|?CHANNEL_NAME??????????????|?MEMBER_ID????????????????????????????|?MEMBER_HOST?|?MEMBER_PORT?|?MEMBER_STATE?|

+---------------------------+--------------------------------------+-------------+-------------+--------------+

|?group_replication_applier?|?d386a328-5494-11eb-8ff3-000c29f06629?|?wallet02????|????????3306?|?ONLINE???????|

|?group_replication_applier?|?da0cec61-549c-11eb-a0a4-000c29bd9bc5?|?wallet01????|????????3306?|?ONLINE???????|

+---------------------------+--------------------------------------+-------------+-------------+--------------+

2?rows?in?set?(0.00?sec)

[root@wallet03?~]#?vi?/etc/my.cnf

[mysqld]

server-id?=?3

gtid_mode?=?on

enforce_gtid_consistency?=?on

log_bin?=?mysql-bin

binlog_format?=?row

binlog_checksum?=?none

binlog_cache_size?=?16M

max_binlog_cache_size?=?4G

max_binlog_size?=?128M

expire_logs_days?=?7

relay_log?=?relay-bin

master_info_repository?=?table

relay_log_info_repository?=?table

log_slave_updates?=?on

slave_parallel_type?=?LOGICAL_CLOCK

slave_parallel_workers?=?4

slave_preserve_commit_order?=?1

plugin_load_add='group_replication.so'

transaction_write_set_extraction?=?XXHASH64

group_replication_group_name?=?"8d1945a5-5c74-4ba0-8240-e9d731110753"

group_replication_start_on_boot?=?off

group_replication_member_weight?=?20

group_replication_local_address?=?"192.168.1.203:20001"

group_replication_group_seeds="192.168.1.201:20001,192.168.1.202:20001,192.168.1.203:20001"

[root@wallet03?~]#?su?-?mysql

[mysql@wallet03?~]$?cd?backup

[mysql@wallet03?backup]$?tar?izxvf?2019-08-22_11-03-21.tar.gz

[mysql@wallet03?backup]$?xtrabackup?--prepare?--target-dir=/home/mysql/backup

[mysql@wallet03?backup]$?xtrabackup?--copy-back?--target-dir=/home/mysql/backup

[mysql@wallet03?backup]$?cat?xtrabackup_binlog_info

mysql-bin.000001????????50523169????????8d1945a5-5c74-4ba0-8240-e9d731110753:1-10759

[root@wallet03?~]#?service?mysqld?start

Logging?to?'/var/lib/mysql/wallet03.err'.

Starting?mysqld:???????????????????????????????????????????[??OK??]

[root@wallet03?~]#?mysql?-uroot?-pabcd@2019

mysql>?set?global?gtid_purged='8d1945a5-5c74-4ba0-8240-e9d731110753:1-10759';

Query?OK,?0?rows?affected?(0.04?sec)

mysql>?change?master?to?master_user='repl',master_password='repl@2019'?for?channel?'group_replication_recovery';

Query?OK,?0?rows?affected,?2?warnings?(0.13?sec)

mysql>?start?group_replication;

Query?OK,?0?rows?affected?(3.39?sec)

mysql>?select?*?from?performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------+-------------+--------------+

|?CHANNEL_NAME??????????????|?MEMBER_ID????????????????????????????|?MEMBER_HOST?|?MEMBER_PORT?|?MEMBER_STATE?|

+---------------------------+--------------------------------------+-------------+-------------+--------------+

|?group_replication_applier?|?d386a328-5494-11eb-8ff3-000c29f06629?|?wallet01????|????????3306?|?ONLINE???????|

|?group_replication_applier?|?da0cec61-549c-11eb-a0a4-000c29bd9bc5?|?wallet02????|????????3306?|?ONLINE???????|

|?group_replication_applier?|?f11984e0-549d-11eb-b271-000c29906702?|?wallet03????|????????3306?|?ONLINE???????|

+---------------------------+--------------------------------------+-------------+-------------+--------------+

3?rows?in?set?(0.00?sec)

mysql>?show?status?like?'group_replication_primary_member';

+----------------------------------+--------------------------------------+

|?Variable_name????????????????????|?Value????????????????????????????????|

+----------------------------------+--------------------------------------+

|?group_replication_primary_member?|?d386a328-5494-11eb-8ff3-000c29f06629?|

+----------------------------------+--------------------------------------+

1?row?in?set?(0.00?sec)

mysql>?select?*?from?performance_schema.replication_group_member_stats\G;

***************************?1.?row?***************************

CHANNEL_NAME:?group_replication_applier

VIEW_ID:?16104300602378309:3

MEMBER_ID:?f11984e0-549d-11eb-b271-000c29906702

COUNT_TRANSACTIONS_IN_QUEUE:?0

COUNT_TRANSACTIONS_CHECKED:?3825

COUNT_CONFLICTS_DETECTED:?0

COUNT_TRANSACTIONS_ROWS_VALIDATING:?18

TRANSACTIONS_COMMITTED_ALL_MEMBERS:?8d1945a5-5c74-4ba0-8240-e9d731110753:1-3851

LAST_CONFLICT_FREE_TRANSACTION:?8d1945a5-5c74-4ba0-8240-e9d731110753:3851

1?row?in?set?(0.00?sec)組復制限制

僅支持innodb引擎的表,能夠創建非innodb引擎的表,但是無法寫入數據,向非innodb表寫數據直接報錯。

mysql>?create?table?tb_myisam(id?int,?name?varchar(50),?primary?key(id))?engine=myisam;

Query?OK,?0?rows?affected?(0.05?sec)

mysql>?insert?into?tb_myisam?select?1,?'1';

ERROR?3098?(HY000):?The?table?does?not?comply?with?the?requirements?by?an?external?plugin.

僅支持innodb引擎的表,并且該表必須有顯式的主鍵,或者非Null的唯一鍵,否則即使能夠創建表,也無法向表中寫入數據。

#?創建沒有主鍵的表,寫入數據失敗

mysql>?create?table?tb_no_primary_key(name?varchar(50));

Query?OK,?0?rows?affected?(0.15?sec)

mysql>?insert?into?tb_no_primary_key?select?'1';

ERROR?3098?(HY000):?The?table?does?not?comply?with?the?requirements?by?an?external?plugin.

#?創建Null唯一索引的表,寫入數據失敗

mysql>?create?table?tb_null_unique_key(name?varchar(50),?unique?key(name));

Query?OK,?0?rows?affected?(0.09?sec)

mysql>?insert?into?tb_null_unique_key?select?'1';

ERROR?3098?(HY000):?The?table?does?not?comply?with?the?requirements?by?an?external?plugin.

#?創建非Null唯一索引的表,寫入數據成功

mysql>?create?table?tb_no_null_unique_key(name?varchar(50)?not?null,?unique?key(name));

Query?OK,?0?rows?affected?(0.04?sec)

mysql>?insert?into?tb_no_null_unique_key?select?'1';

Query?OK,?1?row?affected?(0.06?sec)

Records:?1??Duplicates:?0??Warnings:?0

GTID限制

CREATE?TABLE?…?SELECT語句不支持

因為該語句會被拆分成?CREATE?TABLE?和?INSERT?兩個事務,并且這個兩個事務被分配了同一個?GTID,這會導致?INSERT?被備庫忽略掉。

mysql>?create?table?history01?select?*?from?history;

ERROR?1786?(HY000):?Statement?violates?GTID?consistency:?CREATE?TABLE?...?SELECT.

解決方法

mysql>?create?table?history01?like?history;

Query?OK,?0?rows?affected?(0.32?sec)

mysql>?insert?into?history01?select?*?from?history;

Query?OK,?301277?rows?affected?(7.27?sec)

Records:?301277??Duplicates:?0??Warnings:?0

臨時表事務內部不能執行

創建臨時表語句,但可以在事務外執行,但必須設置?set?autocommit=1?。另外?procedures,?functions,?and?triggers在使用GTID時不能?CREATE?TEMPORARY?TABLE?and?DROP?TEMPORARY?TABLE?語句

mysql>?begin;

Query?OK,?0?rows?affected?(0.00?sec)

mysql>?create?temporary?table?test(id?INT);

ERROR?1787?(HY000):?Statement?violates?GTID?consistency:?CREATE?TEMPORARY?TABLE?and?DROP?TEMPORARY?TABLE?can?only?be?executed?outside?transactional?context.

These?statements?are?also?not?allowed?in?a?function?or?trigger?because?functions?and?triggers?are?also?considered?to?be?multi-statement?transactions.

總結

以上是生活随笔為你收集整理的mysql数据库group_key_【MySQL】数据库复制:组复制(Group Replication)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。