實例主機:
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 [email protected] 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 看同步情況,如果有錯誤也可以看得出來.