多主一從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
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
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
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
[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,這種解決方案已透過測試.希望能夠對你有所幫助.
come from:http://blog.chinaunix.net/u/4312/showart_320014.html
come from:http://blog.chinaunix.net/u/4312/showart_320014.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-629804/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL主從同步(一主一從、一主多從、主從從)等結構的概述與配置MySql主從同步
- MySQL主從同步報Client requested master to start replication from positionMySql主從同步clientAST
- MySQL 5.7 多主一從(多源複製)同步配置MySql
- mysql replication /mysql 主從複製原理MySql
- 《Death Trash》Polygon 前瞻:對老派 RPG 的大膽嘗試Go
- MYSQL資料庫主從同步(一主一從)MySql資料庫主從同步
- mysql主從複製(一):一主多從MySql
- mysql主從同步MySql主從同步
- MySQL多主一從的實現MySql
- Mysql主從同步實戰(一)【知其然】MySql主從同步
- 一種MySQL主從同步加速方案MySql主從同步
- Redis 主從 Replication 的配置Redis
- MySQL主從同步配置MySql主從同步
- 【Mysql】Mariadb多主一從的搭建MySql
- MySQL 資料主從同步MySql主從同步
- MySql主從同步介紹MySql主從同步
- Mysql 主從同步實戰MySql主從同步
- mysql主從同步機制MySql主從同步
- mysql master slave 主從同步MySqlAST主從同步
- mysql 5.7 多主一從的多源複製搭建MySql
- MySQL叢集之 主從複製 主主複製 一主多從 多主一叢 實現方式MySql
- 【mysql】mysql的資料庫主從(一主一從)MySql資料庫
- Redis 主從複製(Replication)Redis
- MySQL 5.7的安裝及主從複製(主從同步)MySql主從同步
- 【MySQL】MySQL Replication 一主一備搭建步驟(GTID方式)MySql
- 【MySQL】MySQL Replication 一主一備搭建步驟(傳統方式)MySql
- MySQL 配置多主一從 ( 8.0.18 版本 )MySql
- MySQL Group Replication小試MySql
- [資料庫]MYSQL主從同步資料庫MySql主從同步
- Mysql 主從同步原理簡析MySql主從同步
- mysql主從同步問題整理MySql主從同步
- MySQL主從同步配置記錄MySql主從同步
- MySQL主從同步加速Transfer–FAQMySql主從同步
- 揭秘MySQL的主從同步實現方案MySql主從同步
- MySQL 主從同步的基本原理MySql主從同步
- MySQL-主從複製之同步主從資料MySql
- Mysql資料庫單向同步(一主兩從)MySql資料庫
- MySQL主從同步校驗與重新同步薦MySql主從同步