安裝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表