实现两台MySQL数据库数据的同步的方法

2019-10-15 22:19:59王振洲


server-id                   = 2                        //本Mysql是slave服务器.h wjC9C'Hu37313master-host             = 192.168.0.1    //master服务器的IPPHPChina 开源社区门户}~q    ~Q_master-user             = root                  //连接master服务器的用户PHPChina 开源社区门户*_B9n(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?$hC*llog-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$c
ak"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"jBn7s*w051031 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查看信息