打开配置文件: vi /usr/local/mysql/var/my.cnf找到一下信息: # required unique id between 1 and 2^32 - 1PHPChina 开源社区门户D%wM/x-Y3U_$zs# defaults to 1 if master-host is not setg~8FPv9W37313# but will not function as a master if omittedML.?K? NZoW37313server-id = 1 //1为master,2为salve添加两行: sql-bin-update-same //同步形式PHPChina 开源社区门户U$m:}s'vbinlog-do-db = abc //要同步的数据库重启192.168.0.1的mysql做事器: /usr/local/mysql/bin/mysqladmin shutdownPHPChina 开源社区门户0w+g!?&P0d U u#Mb i/usr/local/mysql/bin/mysqld_safe --user=mysql &3. 配置Slave做事器 我们的slave做事器紧张是主动去master做事器同步数据回来,我们编辑配置文件: vi /usr/local/mysql/var/my.cnf找到下面类似的信息: # required unique id between 1 and 2^32 - 13FS8oOn lj8o37313# defaults to 1 if master-host is not setPHPChina 开源社区门户9UO7X"TRTGb$Ku# but will not function as a master if omittedcwO @8pmw37313server-id = 1把上面的server-id修正为2,同时添加一些信息: server-id = 2 //本Mysql是slave做事器.h wjC9C'Hu37313master-host = 192.168.0.1 //master做事器的IPPHPChina 开源社区门户}~q ~Q_master-user = root //连接master做事器的用户PHPChina 开源社区门户_Bn(tmaster-password = '' //连接master做事器的密码PHPChina 开源社区门户6O&Ys;rUEmaster-port = 3306 //连接端口S@.@"N&Sb K37313master-connect-retry = 10 //重试次数4`']w^0qW;N2J37313replicate-do-db = abc //要同步的数据库PHPChina 开源社区门户`,Q/C?$hCllog-slave-updates //同步的形式重启192.168.0.2的mysql做事器: /usr/local/mysql/bin/mysqladmin shutdownPHPChina 开源社区门户.wh1]^~!|V$B0\/usr/local/mysql/bin/mysqld_safe --user=mysql &4. 测试安装 首先查看一下slave的主机日志: cat /usr/local/mysql/var/xxxxx_err (xxx是主机名)检讨是否连接正常, 看到类似这样的信息就成功了 051031 11:42:40 mysqld startedPHPChina 开源社区门户W2l0Com R[^ b9S-Rib051031 11:42:41 InnoDB: Started; log sequence number 0 43634PHPChina 开源社区门户UqT7y!Df$cak"BL/usr/local/mysql/libexec/mysqld: ready for connections.PHPChina 开源社区门户;|0G|;vHFZ7}Version: '4.1.15-log' socket: '/tmp/mysql.sock' port: 3306 Source distributionPHPChina 开源社区门户(J9Z,Kg Lx%] i6OW051031 11:42:41 [Note] Slave SQL thread initialized, starting replication in log 'FIRST' PHPChina 开源社区门户Q9n-BU8[AYc LAat position 0, relay log './new4-relay-bin.000001' position: 4PHPChina 开源社区门户j v"jB\n7sw051031 11:43:21 [Note] Slave I/O thread: connected to master 'root@192.168.0.1:3306', ]-{eYn F5vK37313replication started in log 'FIRST' at position 4在Master查看信息 /usr/local/mysql/bin/mysql -u root查看master状态: mysql> show master status;查看Master下mysql进程信息: mysql> show processlist;在slave上查看信息: /usr/local/mysql/bin/mysql -u root查看slave状态: mysql> show slave status;查看slave下mysql进程信息: mysql> show processlist;你再在master的abc库里建立表构造并且插入数据,然后检讨slave有没有同步这些数据,就能够检讨出是否设置成功。 两台MySQL数据库数据的同步方法的内容就先容完了,末了,如果大家有感兴趣的话也可以研究一下关于双击热备份,或者一台master,多台slave的同步实现的内容。