mysql-replication

########主库Master:

vi /etc/my.cnf
[mysqld]
server-id=1
log-bin=masterlog ####日志文件
binlog-do-db=data1 ###要求数据镜像的DB(选填可多行设定,默认同步全部DB)
binlog-ignore-db=mysql ###mysql库不用数据镜像(选填可多行设定,默认同步全部DB)

/usr/local/mysql/bin/mysql -uroot -p
update mysql.user set host='%' where host='127.0.0.1';  ###远程连接DB
show master status;  #######(选记)File:masterlog.000003 , Position:106


#######从库Slave:

vi /etc/my.cnf
[mysqld]
server-id=2
log-bin=slavelog ####日志文件
binlog-do-db=data1 ###要求数据镜像的DB(选填可多行设定,默认同步全部DB)
binlog-ignore-db=mysql ###mysql库不用数据镜像(选填可多行设定,默认同步全部DB)

###数据镜像#########
/usr/local/mysql/bin/mysql -uroot -p
change master to master_host='192.168.1.80',master_user='root', master_password='1',master_log_file='masterlog.000003',master_log_pos=106;
start slave
show slave status\G;

 

###注:可以互为主库双向同步,主库重启后,从库也要跟随重启才能同步!
 

你可能感兴趣的:(vi)