2009年4月3日星期五

mysql5主从备份

这两天在虚机(linux)上搭建了mysql5(imysam)的主从备份机制,廖作记录:

Master
  1. new db :2x_db,and new table: test, input some data;
  2. mysqldump 2x_db to 2x_db_dump.sql,then transfer to slave machine;
  3. modify my.cnf:
log-bin = /var/lib/mysql/master.log
log-bin-index = /var/lib/mysql/master.index.log
binlog-do-db = 2x_db
server-id = 1
   4. start mysql,and create replicate user:
GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%' IDENTIFIED BY 'replicator';

5. flush privileges;
6.show master status,then record this info

Slave:
1. modify my.cnf:
server-id=2
master-host=master machine's ip
master-user=replicator
master-password=replicator
master-log-file=master.000002 // from show master status: logfile
master-log-pos=98 // from show master status: logPos
master-connect-retry=60
replicate-do-db=2x_db

2. start mysql,then new db: 2x_db
3. load 2x_db.sql into 2x_db
4. login in mysql,show slave status

Test:
1. login in master's mysql,insert one record;
2. then login in slave's mysql,select this table;

没有评论:

发表评论