log_bin = /var/log/mysql/mysql-bin.log(系统默认得未改)
server-id =1
#sql-bin-update-same
binlog-do-db=metro
master-user =username
master-password =password
master-connect-retry = 60
read-only = 1
relay-log-purge = 1
replicate-do-db = metro
report-host =192.168.5.7
slave-skip-errors = all
replicate-wild-ignore-table=metro.b
然后进入master数据库的Mysql控制台执行
//全局锁定mysql> slave start;FLUSH TABLES WITH READ LOCK;然后进入另外一个窗口,拷贝db1下所有文件到slave数据库的var目录下//读取相关的二进制文件和偏移量SHOW MASTER STATUS;+---------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+---------------+----------+--------------+------------------+| mysql-bin.003 | 73 | db1 | mysql |+---------------+----------+--------------+------------------+记录下Position 和 File,然后执行//解锁UNLOCK TABLES;然后配置slave数据库的my.cnf中有如下段[mysqld]server-id = 2
master-user =username
master-password =password
master-connect-retry = 60
read-only = 1
relay-log-purge = 1
replicate-do-db = metro
report-host =192.168.5.7
slave-skip-errors = all
replicate-wild-ignore-table=metro.b//不同步的表,例如discuz中的cdb_sessions表然后启动slave数据库,进入mysql控制台,执行slave stop;CHANGE MASTER TO
-> MASTER_HOST='192.168.5.7', //主服务器的IP地址
-> MASTER_USER='username', //同步数据库的用户
-> MASTER_PASSWORD='password', //同步数据库的密码
-> MASTER_LOG_FILE='mysql-bin.003', //主服务器二进制日志的文件名,前面要求记住的参
-> MASTER_LOG_POS=73; //日志文件的开始位置(前面要求记住的参数)
mysql -hlocalhost -uroot
mysql>SHOW SLAVE STATUS/G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: rep1
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000001
Read_Master_Log_Pos: 98
Relay_Log_File: relay.000003
Relay_Log_Pos: 232
Relay_Master_Log_File: binlog.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 98
Relay_Log_Space: 232
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)
可以看到,Slave_IO_Running 和 Slave_SQL_Running 两列的值都为 "Yes",这表明 Slave 的 I/O 和 SQL 线程都在正常运行。
至此,同步设定成功。
另外mysql6.0作为slave时, my.ini只要增加server-id = 3就可以了,其他得属性可以在运行 mysql>change master to master_host='192.168.5.7',master_user='username',master_password='passwor',master_log_file='ccxy_db.000008' ,master_log_pos=98;
配置,如果多写了导致服务无法启动,可以删去,6.0做slave得我也是在windows xp下使用得