Difference between revisions of "System/MySQL/Replication"
Jump to navigation
Jump to search
(Created page with "== MySQL Replication ==") |
|||
| Line 1: | Line 1: | ||
| − | + | = MySQL Replication = | |
| + | |||
| + | == configuration == | ||
| + | |||
| + | Edit /etc/my.cnf to have the following options (change server-id if necessary): | ||
| + | |||
| + | ... | ||
| + | server-id = 1 | ||
| + | log_bin = /var/log/mysql/mysql-bin.log | ||
| + | expire_logs_days = 10 | ||
| + | max_binlog_size = 100M | ||
| + | |||
| + | auto-increment-increment = 2 | ||
| + | auto-increment-offset = 1 | ||
| + | ... | ||
| + | |||
| + | And for each database you want to replicate: | ||
| + | |||
| + | replicate-wild-do-table = db1.% | ||
| + | replicate-wild-do-table = db2.% | ||
| + | ... | ||
| + | |||
| + | |||
| + | == Init and start a slave == | ||
| + | |||
| + | First, on the master, dump the data _with_ the --master-data and --single-transaction parameters: | ||
| + | |||
| + | mysqldump -u root -p --master-data --single-transaction --databases db1 db2 > dump.sql | ||
| + | |||
| + | Then source it on the slave and start slave: | ||
| + | |||
| + | cat dump.sql | mysql -u root -p | ||
| + | mysql -u root -p -e "start slave" | ||
Revision as of 19:03, 5 December 2011
MySQL Replication
configuration
Edit /etc/my.cnf to have the following options (change server-id if necessary):
... server-id = 1 log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M
auto-increment-increment = 2 auto-increment-offset = 1 ...
And for each database you want to replicate:
replicate-wild-do-table = db1.% replicate-wild-do-table = db2.% ...
Init and start a slave
First, on the master, dump the data _with_ the --master-data and --single-transaction parameters:
mysqldump -u root -p --master-data --single-transaction --databases db1 db2 > dump.sql
Then source it on the slave and start slave:
cat dump.sql | mysql -u root -p mysql -u root -p -e "start slave"