6.mysql主-从备份
主-主备份,首先AB机要保持数据一致,即先手工备份A机数据,然后在B机上恢复,之后就很简单了,只需要在B机上创建一个同步账号,并在A机上输入B机的那些参数然后启动slave start就实现了主-主双机热备。
主-从复制如下:
A:192.168.10.119:masterB:192.168.10.118:slave参数说明:需要同步的库名,多个用逗号隔开。binlog-do-db=world,city不需要同步的库名binlog-ignore-db=mysqlMYSQL_A作为主机,MYSQL_B作为从机。在MYSQL_A和MYSQL_B上分别创建好需要同步的数据库在A机上操作vi /etc/my.cnf在mysqld中加入下面server-id=1log-bin=masbinlog-do-db=worldbinlog-ignore-db=mysqlservice mysqld restart同步账号GRANT REPLICATION SLAVE ON *.* TO 'syn'@'192.168.10.118' IDENTIFIED BY '123456';先导入数据mysql < world.sql再锁表FLUSH TABLES WITH READ LOCK;再导出数据mysqldump -uroot -p world >world1.sqlmysql> show master status;+------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------+----------+--------------+------------------+| mas.000002 | 260 | world | mysql |+------------+----------+--------------+------------------+1 row in set (0.00 sec)这里的文件名与位置要在slave中输入。再释放锁unlock tables;在B机上操作server-id=2log-bin=slabinlog-do-db=worldbinlog-ignore-db=mysqlservice mysqld restart先将A机上备份的数据world1.sql导入进来,还原数据,保证二者之间的数据一致。设置主服务器的参数mysql> change master to -> MASTER_HOST='192.168.10.119', -> MASTER_USER='syn', -> MASTER_PASSWORD='123456', -> MASTER_CONNECT_RETRY=60, -> MASTER_LOG_FILE='mas.000002', -> MASTER_LOG_POS=260;Query OK, 0 rows affected (0.19 sec)slave start;show slave status\G;下面是做测试,在A机上删除数据,mysql> delete from City where id<10;Query OK, 6 rows affected (0.07 sec)mysql> show master status;在B机上查看,很快就同步过来了。msyql> show slave status\G;