您好,登錄后才能下訂單哦!
mysql5.7.21開啟Gtid配置主從復制
mysql 主庫master:10.0.0.101 172.168.1.101
mysql 從庫slave:10.0.0.103 172.168.1.103
mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 二進制安裝完成
mysql主庫完整my.cnf配置文件
[root@slave01 ~]# cat /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql/data
back_log = 2000
open_files_limit = 1024
max_connections = 800
max_connect_errors = 3000
max_allowed_packet = 33554432
external-locking = FALSE
character_set_server = utf8
#binlog
log-slave-updates = 1
binlog_format = row
log-bin = /data/mysql/logs/bin-log/mysql-bin
expire_logs_days = 5
sync_binlog = 1
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
#replicate-ignore-db=mysql
skip-name-resolve
slave-skip-errors = 1032,1062
skip_slave_start=1
###relay log
relay-log = /data/mysql/logs/relay-log/relay-bin
relay-log-info-file = /data/mysql/relay-log.info
###slow_log
slow_query_log = 1
slow-query-log-file = /data/mysql/logs/mysql-slow.log
log-error = /data/mysql/logs/error.log
##GTID
server_id = 1103
gtid_mode=on
enforce_gtid_consistency=on
event_scheduler = ON
innodb_autoinc_lock_mode = 1
innodb_buffer_pool_size = 10737418
innodb_data_file_path = ibdata1:10M:autoextend
innodb_data_home_dir = /data/mysql/data
innodb_log_group_home_dir = /data/mysql/data
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_io_capacity = 2000
innodb_log_buffer_size = 8388608
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_open_files = 512
innodb_read_io_threads = 8
innodb_thread_concurrency = 20
innodb_write_io_threads = 8
innodb_lock_wait_timeout = 10
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
key_buffer_size = 3221225472
innodb_log_file_size = 1G
local_infile = 1
log_bin_trust_function_creators = 1
log_output = FILE
long_query_time = 1
myisam_sort_buffer_size = 33554432
join_buffer_size = 8388608
tmp_table_size = 33554432
net_buffer_length = 8192
performance_schema = 1
performance_schema_max_table_instances = 200
query_cache_size = 0
query_cache_type = 0
read_buffer_size = 20971520
read_rnd_buffer_size = 16M
max_heap_table_size = 33554432
bulk_insert_buffer_size = 134217728
secure-file-priv = /data/mysql/tmp
sort_buffer_size = 2097152
table_open_cache = 128
thread_cache_size = 50
tmpdir = /data/mysql/tmp
slave-load-tmpdir = /data/mysql/tmp
wait_timeout = 120
transaction_isolation=read-committed
innodb_flush_log_at_trx_commit=0
lower_case_table_names=1
[mysqldump]
quick
max_allowed_packet = 64M
[mysqld_safe]
log-error = /data/mysql/logs/error.log
pid-file = /data/mysql/mysqld.pid
mysql從庫完整my.cnf配置文件介紹:
mysql的slave從庫的配置文件/etc/my.cnf中參數只是sever_id和主庫的不一樣,其他的參數都保持一致
對于GTID的配置,主要修改配置文件中與GTID特性相關的幾個重要參數(建議使用mysql-5.6.5以上版本),如下:
1、主庫:
[mysqld]
#GTID:
server_id=54
gtid_mode=on
enforce_gtid_consistency=on
#binlog
log_bin=master-binlog
log-slave-updates=1
binlog_format=row
#relay log
skip_slave_start=1
2、從庫:
[mysqld]
#GTID:
gtid_mode=on
enforce_gtid_consistency=on
server_id=197
#binlog
log-bin=slave-binlog
log-slave-updates=1
binlog_format=row
#relay log
skip_slave_start=1
mysql master上操作:
mysql -uroot -p'123456' -e "grant replication slave on *.* to novelrep@'172.168.1.103' identified by 'JuwoSdk21TbUser'; flush privileges;"
[root@master01 ~]# mysqldump -uroot -p'123456' -B -A -F --master-data=2 --single-transaction --events|gzip >/opt/juwo_$(date +%F).sql.gz
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore
GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
mysql slave上操作:
mysql -uroot -p'123456' -e "source /root/juwo_$(date +%F).sql"
主庫上的dump出數據在導入到slave過程中報錯:
ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty
mysql -uroot -p'123456' -e "CHANGE MASTER TO MASTER_HOST='172.168.1.101',MASTER_PORT=3306,MASTER_USER='novelrep',MASTER_PASSWORD='JuwoSdk21TbUser',MASTER_AUTO_POSITION = 1;start slave;show slave
status\G" |grep -i "yes"
slave上執行完以上操作后,show slave status\G,查看到主從復制,slave上的sql線程報錯,主從復制配置失敗
參考一下文檔:
https://www.cnblogs.com/tonnytangy/p/7779164.html
當前GTID_EXECUTED參數已經有值,而從master主庫倒出來的dump文件中包含了SET @@GLOBAL.GTID_PURGED的操作
解決方法:
方法一:reset mater
這個操作可以將當前slave庫的GTID_EXECUTED值置空
方法二:--set-gtid-purged=off
在dump導出master數據時,添加--set-gtid-purged=off參數,避免將master上的gtid信息導出,然后再導入到slave庫
本文檔同時采用了上述2個步驟:
master 庫操作:
mysql -uroot -p'123456' -e "reset mater;"
mysql -uroot -p'123456' -e "grant replication slave on *.* to novelrep@'172.168.1.103' identified by 'JuwoSdk21TbUser'; flush privileges;"
mysqldump -uroot -p'123456' -B -A -F --set-gtid-purged=OFF --master-data=2 --single-transaction --events|gzip >/opt/juwo_$(date +%F).sql.gz
mysql slave上操作:
mysql -uroot -p'123456' -e "source /root/juwo_$(date +%F).sql"
主庫上的dump出數據在導入到slave過程中一切正常
mysql -uroot -p'123456' -e "CHANGE MASTER TO MASTER_HOST='172.168.1.101',MASTER_PORT=3306,MASTER_USER='novelrep',MASTER_PASSWORD='JuwoSdk21TbUser',MASTER_AUTO_POSITION = 1;start slave;show slave
status\G" |grep -i "yes"
slave上執行完以上操作后,show slave status\G,查看到主從復制,slave上的IO線程和sql線程都是yes,到此mysql的GTID模式的主從配置完成
參考文檔:
https://www.2cto.com/database/201801/710551.html
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。