將現(xiàn)有服務(wù)器作為Master服務(wù)器,配置并運(yùn)行一臺(tái)新的MySQL服務(wù)器作為Slave服務(wù)器
log-bin = mysql-bin當(dāng)然關(guān)于MySQL Bin Log的配置還有很多設(shè)置,可以參考相關(guān)手冊(cè)
server-id = 1
mysql> FLUASH TABLES WITH READ LOCK;使用mysqldump導(dǎo)出數(shù)據(jù)
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000157 | 18757860 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql:~# mysqldump -uroot -p --all-databases > dump.sql解鎖
mysql> UNLOCK TABLES;
mysql:~# cat /usr/local/mysql/bin/mysqlbug | grep CONFIGURE
mysql> GREANT REPLICATION SLAVE ON *.* to 'repl'@'IP.SLAVE.SERVER' identified by 'repl_passwd';
./configure; make; make install;
)#mysql_install_db --datadir=/data --user=mysql
目錄中my.cnf文件在
/etc/下創(chuàng)建@my.cnf
下配置@mysqldb
/etc/init.d/mysqldb start
mysql# mysql -uroot -p < dump.sql
如果導(dǎo)入出現(xiàn)超出最大數(shù)據(jù)包錯(cuò)誤可以嘗試修改my.cnf中的max_allow_packet
server-id = 2
master-host = master_ip
master-user = repl
master-password = repl_passwd
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO
MASTER_HOST='masterip',
MASTER_USER='repl',
MASTER_PASSWORD='repl_passwd',
MASTER_LOG_FILE='mysql-bin.000157',
MASTER_LOG_POS=18757860 ;
mysql> START SLAVE;