
This is article 2 of 3 for a MySQL test strategy.
First up, from a redundancy point of view, you're unlikely to want to run a master and a replicated slave instance on the same machine. If the machine goes down you probably lose both. My reason for doing this is specifically for testing during development.
See article 1 for a guide to installing muliple MySQL instances on the same machine. We'll start with a 2 instances, a master and a slave.
- Ensure master and slave instances have a different server-id set (see Setting the Replication Master Configuration and Setting the Replication Slave Configuration)
- Enable binary logging on the master: log-bin=mysql-bin (see Setting the Replication Master Configuration)
- As this is only a test instance the slave will use the root account to access the master access. If this was a production system you'd want to create a replication account with more limited privileges (see Creating a User for Replication).
- Flush and lock the master database:
mysql> FLUSH TABLES WITH READ LOCK; - Obtain the current log position information:
mysql> SHOW MASTER STATUS; - Take a dump of the master database (from another command window):
> mysqldump -u root dbName > dbdump.sql - Unlock the master database:
mysql> UNLOCK TABLES; - Import dump into slave database (assuming your slave instance is running on port 3307):
> mysql --port 3307 -u root dbName < dbdump.sql - Set up the replication link to the master:
mysql> CHANGE MASTER TO MASTER_HOST='localhost', MASTER_USER='root', MASTER_PASSWORD='<password>', MASTER_LOG_FILE='as obtained from step 5', MASTER_LOG_POS=as obtained from step 5; - Start replication:
mysql> START SLAVE; - Check status:
mysql> SHOW SLAVE STATUS\G;
No comments:
Post a Comment