首页 > 代码库 > MySQL主从同步

MySQL主从同步

1.MDB

[client]
port = 3306
socket = /usr/local/mysql/mysql.sock

[mysqld]
port = 3306
socket = /usr/local/mysql/mysql.sock
datadir = /usr/local/mysql/var

server-id = 1
log-bin = /data/mysqllog/binlog/mysql-bin
wait_timeout = 300
expire_logs_days = 10


skip-name-resolve
default-character-set = utf8

back_log = 50
max_connections = 1000
max_connect_errors = 32
max_allowed_packet = 16M

table_cache = 2048
binlog_cache_size = 1M
max_heap_table_size = 64M
tmp_table_size = 64M

key_buffer_size = 32M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M

thread_cache_size = 8
thread_concurrency = 8
thread_stack = 192K

query_cache_size = 64M
query_cache_limit = 2M
tmp_table_size = 64M

ft_min_word_len = 2
default_table_type = INNODB
transaction_isolation = REPEATABLE-READ

log_slow_queries
long_query_time = 2
log_long_format

myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

skip-bdb

innodb_file_per_table = 1
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 0
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[isamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M

[myisamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open-files-limit = 8192

2.SDB和MDB一样,添加以下字段:

server-id = 291   #serverid不能和master一样。
master-host = 192.168.7.14  #MDBip
master-port = 3306
master-user = xxx     #MDB授权sdb同步的账号
master-password = UJLpaX36VhnBx25m   #密码
master-connect-retry = 30 

replicate-ignore-db = mysql
replicate-ignore-db = txwy_s1_50hero_combats    #表示同步的时候忽略此库。
#replicate-do-db = sanguo

log-bin = /data/mysqllog/binlog/mysql-bin
wait_timeout = 300
expire_logs_days = 10
slave-skip-errors = 1062


relay-log = /data/mysqllog/relaylog/relay
max-relay-log-size = 255M
relay-log-space-limit = 10240M
relay-log-index = /data/mysqllog/relaylog/relay
relay-log-info-file = /data/mysqllog/relaylog/relay-log.info
master-info-file = /data/mysqllog/relaylog/master.info   ####binlog日志、

 3.配置主从同步:

#在MDB上执行

        mysql -uxxx -pxxx -h127.0.0.1 -e "show master status \G;"

        查看当前binlog值和pos值

        例如:

技术分享

#在SDB上执行

       mysql -uxxx -pxxx -h127.0.0.1

       >slave stop;

       >change master to master_log_file=‘mysql-bin.000001‘,master_log_pos=582783685;

       提示ok之后执行

       >slave start

       查看是否同步

       >show slave status \G;

MySQL主从同步