# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
innodb_buffer_pool_size = 2048M
innodb_thread_concurrency=8
basedir =/usr/local/mysql
datadir=/app/mysql/data
socket= /usr/local/mysql/tmp/mysql.sock
tmpdir = /tmp
user = mysql
max_allowed_packet = 100M
skip-name-resolve
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
port=3306
collation-server = utf8mb4_general_ci
lower_case_table_names=1
character-set-server = utf8mb4
max_connections=3600
# log-bin=mysql-bin
server-id=11
#### gtid ####
gtid_mode = on
# 强制gtid一致性
enforce_gtid_consistency = 1
binlog_gtid_simple_recovery = 1
#### log ####
log_timestamps=system
log_bin_index = /app/mysql/log/mysql-bin.index
# 默认为mixed混合模式,更改成row复制,为了数据一致性
binlog_format = row
relay_log_recovery=ON
relay_log=/app/mysql/log/mysql-relay-bin
relay_log_index=/app/mysql/log/mysql-relay-bin.index
log_error = /app/mysql/log/mysql-error.log
# binlog过期时间
expire_logs_days=30
# 从库binlog才会记录主库同步的操作日志
log-slave-updates = 1
# 开启二进制日志
log_bin = /app/mysql/log/mysql-bin
#### replication ####
replicate_wild_ignore_table = information_schema.%,performance_schema.%,sys.%
#### semi sync replication settings #####
plugin_dir=/usr/local/mysql/lib/plugin
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld_safe]
log-error=/app/mysql/log/mysqld.log
pid-file=/app/mysql/run/mysqld.pid
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
innodb_buffer_pool_size = 2048M
innodb_thread_concurrency=8
basedir =/usr/local/mysql
datadir=/app/mysql/data
socket= /usr/local/mysql/tmp/mysql.sock
tmpdir = /tmp
user = mysql
max_allowed_packet = 100M
skip-name-resolve
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
port=3306
collation-server = utf8mb4_general_ci
lower_case_table_names=1
character-set-server = utf8mb4
max_connections=3600
# log-bin=mysql-bin
server-id=12
# 以防人为误操作从库数据
read_only= 1
gtid_mode = on
enforce_gtid_consistency = 1
binlog_gtid_simple_recovery = 1
log_timestamps=system
log_bin_index = /app/mysql/log/mysql-bin.index
binlog_format = row
relay_log_recovery=ON
relay_log=/app/mysql/log/mysql-relay-bin
relay_log_index=/app/mysql/log/mysql-relay-bin.index
log_error = /app/mysql/log/mysql-error.log
expire_logs_days=30
log-slave-updates = 1
log_bin = /app/mysql/log/mysql-bin
replicate_wild_ignore_table = information_schema.%,performance_schema.%,sys.%
plugin_dir=/usr/local/mysql/lib/plugin
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld_safe]
log-error=/app/mysql/log/mysqld.log
pid-file=/app/mysql/run/mysqld.pid
cnf相关配置含义:
出现:Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ ,则需要重新建立一下软链接:ln -s /usr/local/mysql/tmp/mysql.sock /tmp/mysql.sock
mysql -uroot -p
CREATE USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'dsdfd..';
GRANT replication slave,replication client ON *.* TO 'slave'@'%';
flush privileges;
mysql -uslave -pdsdfd.. -h192.168.100.30
show master status;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql-bin.000001 | 3291 | | | fc28cb61-b371-11ed-9426-000c29a77e07:1-6 |
+------------------+----------+--------------+------------------+------------------------------------------+
# 停止从库
mysql> stop slave;
# 重置主从配置
mysql> reset slave all;
# slave节点登录MySQL与master 进行关联,file和pos取主库日志信息
mysql> change master to master_host='192.168.77.128',master_port=3306,master_user='slave',master_password='dsdfd..', master_log_file='mysql-bin.000001',master_log_pos=3291;
# 启动
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.77.128
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 3291
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 2774
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: information_schema.%,performance_schema.%,sys.%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 3291
Relay_Log_Space: 2982
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: 11
Master_UUID: fc28cb61-b371-11ed-9426-000c29a77e07
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: fc28cb61-b371-11ed-9426-000c29a77e07:4-6
Executed_Gtid_Set: fc28cb61-b371-11ed-9426-000c29a77e07:4-6
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set (0.00 sec)
# 从库使用mysqldump远程导出数据库
mysqldump -uasi -pAss6.. -h192.125.86.52 --all-databases --master-data=2 --single-transaction --quick --set-gtid-purged=ON --force > /app/mysql/dump/as3d.sql
# 查看导出来的puraged情况
grep GTID_PURGED /app/mysql/dump/as3d.sql
# 从库设置puraged,告诉从库不需要执行这批次事务
SET @@GLOBAL.GTID_PURGED='78336cdc-8cfb-11e6-ba9f-000c29328504:1-38';
# 登录从库执行reset master,重置从库的binlog
mysql> reset master;
# 导入主库数据
mysql -uroot -pcodesnake < /app/mysql/dump/as3d.sql
# 查询从库数据是否正常
mysql> show databases;
# 查看dump出来的log_pos
head -n 100 /app/mysql/dump/as3d.sql
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=4805477;
# 执行change master关联到主库
mysql> change master to master_host='192.125.86.52',master_port=3306,master_user='slave',master_password='dsdfd..', master_log_file='mysql-bin.000001',master_log_pos=4805477;
mysql> start slave;
mysql> show slave status \G;