安装mysql
http://www.javashuo.com/article/p-xxaznxst-ck.html
修改my.cnf,增长server-id=133和log_bin=chinantfy1
修改完配置文件后,启动或者重启mysqld服务mysql
service mysqld restart ls /data/mysql
把mysql库备份并恢复成chinantfy库,做为测试数据sql
mysqldump -uroot -p123456 mysql > /tmp/mysql.sql mysql -uroot -p123456 -e 'create database chinantfy' mysql -uroot -p123456 chinantfy < /tmp/mysql.sql
建立用做同步数据的用户vim
mysql -uroot -p123456 grant replication slave on *.* to 'repl'@192.168.127.134 identified by '123456'; flush tables with read lock; show master status;
chinantfy1.000001 665002服务器
安装mysql
查看my.cnf,配置server-id=134,要求和主不同
修改完配置文件后,启动或者重启mysqld服务ide
vim /etc/profile export PATH=$PATH:/usr/local/mysql/bin/
把主上chinantfy库同步到从上测试
scp @192.168.127.133:/tmp/mysql.sql /tmp/chinantfy.sql
能够先建立chinantfy库,而后把主上的/tmp/mysql.sql拷贝到从上,而后导入chinantfy库线程
mysql -uroot -e 'create database chinantfy' mysql -uroot chinantfy </tmp/chinantfy.sql
mysql -uroot stop slave; change master to master_host='192.168.127.133', master_user='repl', master_password='123456', master_log_file='chinantfy1.000001', master_log_pos=665002; //ip是主的ip start slave;
还要到主上执行3d
unlock tables;
从上执行mysql -uroot
show slave status\G
看是否有
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
还需关注
Seconds_Behind_Master: 0 //为主从延迟的时间
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:rest
主服务器上
binlog-do-db= //仅同步指定的库
binlog-ignore-db= //忽略指定库
从服务器上
replicate_do_db=
replicate_ignore_db=
replicate_do_table=
replicate_ignore_table=
replicate_wild_do_table= //如chinantfy.%, 支持通配符%
replicate_wild_ignore_table=code
主上 mysql -uroot chinantfy
select count() from db;
truncate table db;
到从上 mysql -uroot chinantfy
select count() from db;
主上继续drop table db;
从上查看db表