首页 >数据库 >mysql教程 >MySQL单向同步实现_MySQL

MySQL单向同步实现_MySQL

WBOY
WBOY原创
2016-06-01 13:47:161355浏览

bitsCN.com

实例主机:
dbasky=192.168.1.120
dbaskyback=192.168.1.121

目的:dbaskyback的主机去同步dbasky主机test库上的数据

安装mysql
[root@dbasky]#wget ftp://ftp.cronyx.ru/pub/FreeBSD/ports/distfiles/mysql-5.0.45.tar.gz
[root@dbasky]#cd /usr/local/mysql-5.0.45
[root@dbasky]#groupadd mysql
[root@dbasky]#useradd -g mysql mysql
[root@dbasky]#mkdir /opt/mysql-data
[root@dbasky]#CFLAGS="-O3 " CXX=gcc CXXFLAGS="-O3 -felide-constructors
 -fno-exceptions -fno-rtti" ./configure             --prefix=/usr/local/mysql --enable-assembler             --with-charset=utf8             --with-extra-charsets=gbk,gb2312,latin1             --localstatedir=/opt/mysql-data             --with-mysqld-user=mysql --enable-large-files --with-big-tables             --without-debug --enable-thread-safe-client             --with-fast-mutexes             --with-innodb
[root@dbasky]#make
[root@dbasky]#make install
[root@dbasky]#cd /etc
[root@dbasky]#rz my.cnf
[root@dbasky]#chown -R mysql .
[root@dbasky]#chgrp -R mysql .
[root@dbasky]#chown -R mysql /opt/mysql-data
[root@dbasky]#chgrp -R mysql /opt/mysql-data
[root@dbasky]#bin/mysql_install_db --user=mysql
[root@dbasky]#chown -R root .
[root@dbasky]#bin/mysqld_safe --user=mysql &
[root@dbasky]#cd  /usr/local/mysql
[root@dbasky]#echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@dbasky]#echo "export PATH" >> /etc/profile
[root@dbasky]#echo "alias vi="vim"" >> /etc/profile
[root@dbasky]#echo "/usr/local/mysql/lib/mysql" > /etc/ld.so.conf.d/mysql.conf

在dbasky机器上
建立用户
mysql>create database test;
mysql>grant all on *.* to xu@192.168.1.121 identified by 123456;

     [root@dbasky]#vi /etc/my.cnf
     server-id=1 #为master
     log-bin=/var/log/mysql/mysql.log
添加
    binlog-do-db=test #要同步的数据库名字

重新启动mysql
用 mysql>show master status 查看

在dbaskyback机器上
dbaskyback#vi /etc/my.cnf
  server-id=2 #为slave
  master-host=192.168.1.120
  master-user=xu
  master-password=123456
  master-port=3306
  master-connect-retry=60 #间隔60秒重新设置
  replicate-do-db=test

用mysql>show slave status 看同步情况,如果有错误也可以看得出来.

 

bitsCN.com
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn