mysql copy

主从数据库人COPY
注意 mysql 数据库的版本,两个数据库版本要相同,或者slave比master版本低
环境 :
Master:192.168.25.58
Slave :192.168.25.59
Master 配置
vim /etc/my.cnf
log-bin=mysql-bin (启动二进制日志)
server-id = 1      (服务器Id要是唯一的)
binlog-do-db=test1
binlog-do-db=epg # 二进制需要同步的数据库名q
#binlog-ignore-db =mysql #避免同步mysql用户配置,以免不必要的麻烦
[root@localhost home]# service mysqld restart
 
 
Mysql
[root@localhost xiao]#mysqladmin –u root –proot password 123456 (更改root密码)
[root@localhost xiao]# mysqld_safe     - -skip-grant-tables   --ship-network (root密码不记得了)
mysql> grant replication client, replication slave on *.* to xiao@'192.168.25.%' identified by '123456';
mysql> use test1
mysql> create table xiao5(id int(2), name varchar(20));
mysql> flush privileges;
mysql> show master status;
mysql> set sql_log_bin=0; (关闭二进制日志)
mysql> source /tmp/epg.sql;
[root@localhost home]# mysql -uroot -proot epg < epg.sql
mysql> set sql_log_bin=1 (启动二进制日志)
[root@localhost home]# mysqldump -uroot -proot --all-databases --lock-all-tables --master-data=2 >slave.sql
slave配置
vim /etc/my.cnf
server-id=2
replicate-do-db=test1,
replicate-do-db=epg
replicate-ignore-db=mysql,
[root@localhost xiao]# service mysqld restart
[root@localhost xiao]# scp -r [email protected]:/home/slave.sql ./
[root@localhost xiao]# mysql -uroot –proot
[root@localhost xiao]# mysql -uroot -proot <slave.sql
[root@localhost xiao]# head slave.sql
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000006', MASTER_LOG_POS=106;
[root@localhost xiao]# mysql -uroot –proot
mysql> change master to master_host='192.168.25.58',master_user='xiao', master_password='123456', master_log_file='mysql-bin.000006',master_log_pos=106;
 
mysql> start slave;
mysql> show slave status \G
mysql> show processlist;
 
主主数据库COPY
修改原slave
[root@localhost mysql]# vim /etc/my.cnf
log-bin=mysql-bin
binlog-do-db=test1
binlog-do-db=epg
mysql> grant replication client, replication slave on *.* to xiao@'192.168.25.%' identified by '123456';
mysql> flush privileges;
 
修改原master
[root@localhost mysql]# vim /etc/my.cnf
replicate-do-db = test1
replicate-do-db = epg
mysql> change master to master_host='192.168.25.59',master_user='xiao', master_password='123456';
mysql> start slave;
 

你可能感兴趣的:(数据库)