多主一从mysql replication同步表的大胆尝试.
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多主一从mysql replication同步表的大胆尝试.相关的知识,希望对你有一定的参考价值。
能否将不同机器上的不同库中的表同步到同一个机器的同一个库中?表是不同的.而且对于slave这台机子来说,这些表只用来读.
同步不同库的表很简单了,用
replicate-do-table=db_name.tbl_name
多个不同机子上的不同库的表同步到同一个机子的同一个库中,再加上下面这句.
replicate-rewrite-db=from_name->to_name
配置slave 上的my.cnf
cat my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
[mysqld1]
port = 3306
socket = /tmp/mysql.sock1
skip-locking
pid-file=/usr/local/mysql/data/test-db1a.pid
datadir = /usr/local/mysql/data
log=/usr/local/mysql/data/test-db1.log
user = mysql
log-slow-queries=/usr/local/mysql/data/slowquery1.log
long_query_time = 2
key_buffer = 256M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
myisam_sort_buffer_size = 64M
thread_cache = 32
query_cache_size = 32M
thread_concurrency = 2
max_connections=500
server-id = 2
master-host = 192.168.0.1
master-user = ‘replcate‘
master-password = ‘1234567890‘
master-port = 3306
report-host = test-db3
master-connect-retry = 30
log-bin
log-slave-updates
replicate-rewrite-db=from_name->to_name
replicate-do-table=db_name.tbl_name
[mysqld2]
port = 3307
socket = /tmp/mysql.sock2
pid-file = /usr/local/mysql/data/test-db2b.pid
datadir = /usr/local/mysql/data
log=/usr/local/mysql/data/test-db2.log
user = mysql
log-slow-queries=/usr/local/mysql/data/slowquery2.log
long_query_time = 10
key_buffer = 128M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 1M
read_buffer_size = 1M
myisam_sort_buffer_size = 32M
thread_cache = 32
query_cache_size = 16M
thread_concurrency = 2
max_connections=300
server-id = 2
master-host = 192.168.0.2
master-user = ‘repl‘
master-password = ‘1234567890‘
master-port = 3307
report-host = test-db3
master-connect-retry = 30
log-bin
log-slave-updates
replicate-rewrite-db=from_name->to_name
replicate-do-table=db_name.tbl_name
好了,看看上面配置,明白了两个mysqld实例用了相同的库表文件,会不会有问题呢?
当然,使用不当的话会有问题,首先要符合两个实例读写的对象没有交叉.(同步过来的表唯一),其次选择合适的存储引擎,MYISM比innodb从理论上更适合这种应用.再次使用过程中对slave上的两个mysqld实例,只使用一个进行本机其它库表(非同步过来的)写操作.
ok,这种解决方案已通过测试.
来源: http://blog.chinaunix.net/uid-220350-id-149202.html
以上是关于多主一从mysql replication同步表的大胆尝试.的主要内容,如果未能解决你的问题,请参考以下文章