Environment
ubuntu server & debian latest version.
Server A IP:sora.kasugano.us
Server B IP:evo4.kasugano.us
Config Master Server A:
Edit config file: /etc/mysql/my.cnf
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
report-host = kasugano.us
expire_logs_days = 10
max_binlog_size = 100M
binlog_do_db = datalife_kasugano //Here is only sync table datalife_kasugano.Using ',' to separate multi-tables if it doesn't work,try seperate to two line
#Binlog_Do_DB: db2
#binlog_ignore_db = include_database_name
Create a account for replicat operation
MySQL> GRANT REPLICATION SLAVE ON *.*
-> TO 'repl'@'%.kasugano.us' IDENTIFIED BY 'slavepass';
Restart Mysql Service:
service mysqld restart
Lock tables:
MySQL> FLUSH TABLES WITH READ LOCK;
then backup datebase and transfer tables to Server B
there is 2 methord to backup tables:
1.zip the /var/lib/mysql/tablename
2.use MySQLdump with '--master-data'
Find the master status and record the value of file and position
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000009
Position: 106
Binlog_Do_DB: datalife_kasugano
Binlog_Ignore_DB:
1 row in set (0.00 sec)
Unlock tables:
MySQL> UNLOCK TABLES;
Config Slave Server B:
Edit config file: /etc/mysql/my.cnf
server-id = 2 //This value should be different from Server A.
log_bin = /var/log/mysql/mysql-bin.log
master-host = kasugano.us
master-port = 3306
master-user = repl
master-password = slavepass
master-connect-retry = 120
report-host = sora.kasugano.us
expire_logs_days = 10
max_binlog_size = 100M
binlog_do_db = datalife_kasugano
#binlog_ignore_db = include_database_name
Restart Mysql Service:
service mysqld restart
See the slave status and it should like this:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: sora.kasugano.us
Master_User: repl
Master_Port: 3306
Connect_Retry: 120
Master_Log_File: mysql-bin.000009
Read_Master_Log_Pos: 106
Relay_Log_File: mysqld-relay-bin.000026
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 106
Relay_Log_Space: 552
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
if
Slave_IO_Running: No
Slave_SQL_Running: No
then
check sync account's privileges
if
Slave_IO_Running: Yes
Slave_SQL_Running: No
then
MySQL> slave stop; //stop slave service
Config master server's parameters
MySQL> change master to master_host='sora.kasugano.us', master_user='repl', master_password='slavepass', master_port=3306, master_log_file='mysql-bin.000009', master_log_pos=106;
MySQL> slave start; //start slave service
then set B as Master,A as Slave do the above process again.
ref.
简单实现MySQL数据库双机热备份的方案 http://www.linuxidc.com/Linux/2007-04/3348.htm
实现两个Mysql数据库同步 http://blog.csdn.net/nuanchun666/archive/2008/01/28/2069301.aspx
MYSQL同步 Slave_IO_Running: No 或者Slave_SQL_Running: No 解决办法 http://comtv.blog.51cto.com/17037/553248