MySQL主从同步配置

MySQL主从配置文件

主库配置

[client]
port            = 13309
socket          = /data/mysqldata/mysql.sock
default-character-set = utf8mb4
[mysql]
no-auto-rehash
[mysqld]

user    = mysql
port    = 13309
socket  = /data/mysqldata/mysql.sock
basedir = /usr
datadir = /data/mysqldata/data
pid-file=/data/mysqldata/mysqld.pid
skip-federated
skip-blackhole
skip-name-resolve
skip_external_locking
flush=OFF
sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION  
event-scheduler=ON
default-storage-engine=InnoDB
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
lower_case_table_names=1
explicit_defaults_for_timestamp
group_concat_max_len=1048576
back_log=1000
max_connections=1000
max_user_connections=800
thread_cache_size=128
max_connect_errors=99999
wait_timeout=172800
interactive_timeout=172800
net_buffer_length=32K
max_allowed_packet=64M
max_heap_table_size=500M
tmp_table_size=2M
sort_buffer_size=8M
max_length_for_sort_data=16k
join_buffer_size=4M
read_rnd_buffer_size=8M
table_open_cache=10240
table_open_cache_instances=16
query_cache_type=0   
query_cache_size=0   
general_log_file=/data/mysqldata/data/general.log
log-error=/data/mysqldata/error2.log
long_query_time=2
slow_query_log
slow_query_log_file=/data/mysqldata/data/slow-query.log
log-bin-index=/data/mysqldata/data/mysql-bin.index
log-bin=/data/mysqldata/data/mysql-bin
relay-log-index=/data/mysqldata/data/mysql-relay-bin.index
relay-log=/data/mysqldata/data/mysql-relay-bin
binlog_cache_size=256K
max_binlog_size=512M
binlog-format=ROW
binlog_rows_query_log_events=ON
binlog_row_image=minimal
binlog-checksum=CRC32
sync_binlog=10
expire_logs_days=10
log_slave_updates=1
log_bin_trust_function_creators=1
auto_increment_increment=1
auto_increment_offset=1
allow-suspicious-udfs
innodb_support_xa=1             
sysdate-is-now
#slave_skip_errors=all
key_buffer_size=8M
bulk_insert_buffer_size=16M
myisam_sort_buffer_size=32M
myisam_max_sort_file_size=2G
myisam_repair_threads=1
myisam-recover-options=default
read_buffer_size=1M
innodb_buffer_pool_size= 6G
innodb_buffer_pool_instances=8
innodb_max_dirty_pages_pct=40
innodb_sort_buffer_size=16M
innodb_data_home_dir=/data/mysqldata/data
innodb_data_file_path=ibdata1:4096M:autoextend
innodb_autoextend_increment=128
innodb_file_per_table
innodb_open_files=21490
innodb_fast_shutdown=1
innodb_force_recovery=0
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=64M
innodb_log_file_size=1G
innodb_log_files_in_group=2
innodb_log_group_home_dir=/data/mysqldata/data
innodb_adaptive_flushing_lwm=30
innodb_read_io_threads=8
innodb_write_io_threads=8
innodb_flush_method=O_DIRECT
innodb_flush_neighbors=2
innodb_lru_scan_depth=1024
innodb_change_buffering=all
innodb_purge_threads
innodb_commit_concurrency=0
innodb_thread_concurrency=0
innodb_concurrency_tickets=1024
innodb_autoinc_lock_mode=1
innodb_stats_on_metadata=0
innodb_lock_wait_timeout=300
innodb_rollback_on_timeout=1
innodb_max_undo_log_size=1G
innodb_undo_directory=/data/mysqldata/data
innodb_undo_log_truncate=1
innodb_undo_logs=128
innodb_undo_tablespaces=4
innodb_purge_rseg_truncate_frequency=128
gtid_mode=on
enforce-gtid-consistency
server-id = 18794
#不需要同步的数据库
binlog-ignore-db=mysql
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
pid-file=/data/mysqldata/mysqld.pid

从库配置

[client]
port = 13309
socket = /data/mysqldata/mysql.sock
default-character-set = utf8mb4
[mysql]
no-auto-rehash
[mysqld]
user    = mysql
port    = 13309
socket  = /data/mysqldata/mysql.sock
basedir = /usr
datadir = /data/mysqldata/data
pid-file=/data/mysqldata/mysqld.pid
skip-federated
skip-blackhole
skip-name-resolve
skip_external_locking
flush=OFF
sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION  
event-scheduler=ON
default-storage-engine=InnoDB
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
lower_case_table_names=1
explicit_defaults_for_timestamp
group_concat_max_len=1048576
back_log=1000
max_connections=1000
max_user_connections=800
thread_cache_size=128
max_connect_errors=99999
wait_timeout=172800
interactive_timeout=172800
net_buffer_length=32K
max_allowed_packet=64M
max_heap_table_size=500M
tmp_table_size=2M
sort_buffer_size=8M
max_length_for_sort_data=16k
join_buffer_size=4M
read_rnd_buffer_size=8M
table_open_cache=10240
table_open_cache_instances=16
query_cache_type=0   
query_cache_size=0   
general_log_file=/data/mysqldata/data/general.log
log-error=/data/mysqldata/error.log
long_query_time=2
slow_query_log
slow_query_log_file=/data/mysqldata/data/slow-query.log
log-bin-index=/data/mysqldata/data/mysql-bin.index
log-bin=/data/mysqldata/data/mysql-bin
relay-log-index=/data/mysqldata/data/mysql-relay-bin.index
relay-log=/data/mysqldata/data/mysql-relay-bin
binlog_cache_size=256K
max_binlog_size=512M
binlog-format=ROW
binlog_rows_query_log_events=ON
binlog_row_image=minimal
binlog-checksum=CRC32
sync_binlog=10
expire_logs_days=10
log_slave_updates=1
log_bin_trust_function_creators=1
auto_increment_increment=1
auto_increment_offset=1
allow-suspicious-udfs
innodb_support_xa=1             
sysdate-is-now
#slave_skip_errors=all
key_buffer_size=8M
bulk_insert_buffer_size=16M
myisam_sort_buffer_size=32M
myisam_max_sort_file_size=2G
myisam_repair_threads=1
myisam-recover-options=default
read_buffer_size=1M
innodb_buffer_pool_size= 6G
innodb_buffer_pool_instances=8
innodb_max_dirty_pages_pct=40
innodb_sort_buffer_size=16M
innodb_data_home_dir=/data/mysqldata/data
innodb_data_file_path=ibdata1:4096M:autoextend
innodb_autoextend_increment=128
innodb_file_per_table
innodb_open_files=21490
innodb_fast_shutdown=1
innodb_force_recovery=0
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=64M
innodb_log_file_size=1G
innodb_log_files_in_group=2
innodb_log_group_home_dir=/data/mysqldata/data
innodb_adaptive_flushing_lwm=30
innodb_read_io_threads=8
innodb_write_io_threads=8
innodb_flush_method=O_DIRECT
innodb_flush_neighbors=2
innodb_lru_scan_depth=1024
innodb_change_buffering=all
innodb_purge_threads
innodb_commit_concurrency=0
innodb_thread_concurrency=0
innodb_concurrency_tickets=1024
innodb_autoinc_lock_mode=1
innodb_stats_on_metadata=0
innodb_lock_wait_timeout=300
innodb_rollback_on_timeout=1
innodb_max_undo_log_size=1G
innodb_undo_directory=/data/mysqldata/data
innodb_undo_log_truncate=1
innodb_undo_logs=128
innodb_undo_tablespaces=4
innodb_purge_rseg_truncate_frequency=128
gtid_mode=on
enforce-gtid-consistency
server-id = 1946117
#不需要同步数据库
binlog-ignore-db=mysql
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
pid-file=/data/mysqldata/mysqld.pid

主库执行命令

show master status;


#创建主从同步用户,并授权
create user repl;

grant replication slave on *.* to 'repl'@'127.0.0.1'identified by '123456';

flush privileges;

从库执行命令

#从库设置主从同步信息
change master to master_host='127.0.0.1',
master_port=3306,master_user='test',
master_password='123456',
master_log_file='master-bin.000002',
master_log_pos=120;

#开启主从同步
start slave;

#暂停主从同步
stop slave;

#查看主从同步状态
show slave status \G

授权远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;

#从库加入master主库同步用户信息
master-host=192.168.8.10
master-user=rep
master-password=123456
master-port=3306

你可能感兴趣的:(MySQL主从同步配置)