首先准备两台服务器(双机,单机的暂不考虑),例如,局域网IP分别为192.168.0.231 主服务器(ServerData) ,192.168.0.16 从服务器(SlaveData),保证两台机器能互相连接,都有权限,这里就以root为例。
备份其中一个数据库,还原到另外的一个机器上,然后在 主服务器 mysql安装文件的 my.ini 的 mysqld节点下面 写上
server-id=1(主服务器ID,不能重复)
binlog-do-db=newday(要复制的库)
log-bin="e:/mysql/log"(log文件存放处,最后的参数表明日志文件名,replication是基于log来实现复制的)
#replication slave
master-host=192.168.0.16(设置要周步的主机名,即SB)
master-port=3306
master-user=root(replication时要用到的用户名)
master-password=123456(replication时要用到的对应密码)
replicate-do-db=newday(要复制的库)
master-connect-retry=60(连接时间)
然后在 从服务器 mysql安装文件的 my.ini 的 mysqld节点下面 写上
server-id=2(从服务器ID,不能重复)
binlog-do-db=newday(要复制的库)
log-bin="e:/mysql/log"(log文件存放处,最后的参数表明日志文件名,replication是基于log来实现复制的)
#replication slave
master-host=192.168.0.231(设置要周步的主机名,即SB)
master-port=3306
master-user=root(replication时要用到的用户名)
master-password=123456(replication时要用到的对应密码)
replicate-do-db=newday(要复制的库)
master-connect-retry=60(连接时间)
然后重启MYSQL服务。
3.1进入主服务器,从服务器,停止slave服务,命令如下
mysql> slave stop
分别执行 mysql>show master status/G
mysql> show master status/G
*************************** 1. row ***************************
File: log.000010
Position: 722
Binlog_Do_DB: newday
Binlog_Ignore_DB:
1 row in set (0.00 sec)
记录下File:Position信息,同时查看Binlog_Do_DB信息是否为我们要replication的库
查看slave status,命令如下:
mysql> show slave status/G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.231
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: log.000007
Read_Master_Log_Pos: 515
Relay_Log_File: peter-relay-bin.000003
Relay_Log_Pos: 245
Relay_Master_Log_File: log.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: newday
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: 515
Relay_Log_Space: 948
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
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
查看Slave_IO_Running: Slave_SQL_Running:是否同时为YES,如果不是,刚需要重新配置。
修改配置之后 要删除 mysql数据库文件下的 master.info文件之后重启MYSQL服务才生效。