mysql互为主从

主库

#vi /etc/my.cnf

log-bin=mysql

server-id=178

#service mysqld restart

#mysql -uroot -p******

mysql>show master status\G;   查看position (便于后面备份)

mysql>grant replication slave on *.* to slave@192.168.0.66  identified by '******' 为slave用户授权。

mysql>grant replication slave on *.* to slave@192.168.0.178  identified by '******' 为slave用户授权。

mysql>change master to

mysql>master_host = '192.168.0.66',

mysql>master_user ='slave',

mysql>master_password='******',

mysql>master_log_file ='mysql.000001',

mysql>master_log_pos =106;

mysql>slave start;  启动同步。

从库

#vi /etc/my.cnf

log-bin=mysql

server-id=66

#service mysqld restart

#mysql -uroot -p******

mysql>show master status\G;

mysql>change master to

mysql>master_host = '192.168.0.178',

mysql>master_user ='slave',

mysql>master_password='******',

mysql>master_log_file ='mysql.000001',

mysql>master_log_pos =106;

mysql>slave start;  启动同步。