注意在導出數據以前先對主數據庫進行
READ LOCK
,以保證數據的一致性
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.19 sec)
以後是
mysqldump
mysqldump -S /data/mysql_3306/mysql.sock > master.sql
最好在主數據庫備份完畢,恢復寫操做
mysql> unlock tables;
Query OK, 0 rows affected (0.28 sec)
(6)
將剛纔主數據備份的
master.sql
複製到從數據庫,進行導入
(7)
接着修改從數據庫的
my.cnf,
增長
server-id
參數
,
指定複製使用的用戶
,
主數據庫服務器的
ip,
端口以及開始執行復制日誌的文件和位置
[mysqld]
server-id=2
log_bin = mysql-bin
#master-host=172.16.1.119
#master-user=root
#master-password=111111
#master-port=3306
#以上註釋的緣由:
Mysql版本從5.1.7之後開始就不支持「master-host」相似的參數;
查看mysql_error.log中的報錯信息以下;
110105 13:38:00 mysqld_safe mysqld from pid file /data/mysql_3306/mysql.pid ended
110105 13:38:06 mysqld_safe Starting mysqld daemon with databases from /data/mysql_3306/data
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
110105 13:38:06 InnoDB: highest supported file format is Barracuda.
110105 13:38:06 InnoDB Plugin 1.0.6 started; log sequence number 44309
110105 13:38:06 [ERROR] /usr/local/webserver/mysql/libexec/mysqld: unknown variable 'master-host=192.168.7.202'
110105 13:38:06 [ERROR] Aborting
110105 13:38:06 InnoDB: Starting shutdown...
110105 13:38:08 InnoDB: Shutdown completed; log sequence number 44319
110105 13:38:08 [Note] /usr/local/webserver/mysql/libexec/mysqld: Shutdown complete
因此只能註釋掉
replicate-do-db=zone
replicate-do-db=zone_credits
replicate-do-db=zone_main
replicate-do-db=zone_mood
(8)
在從服務器上
,
啓動
slave
進程
當我在執行start slave這條命令時,系統提示
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO,
執行show slave status;又提示Empty set (0.00 sec),想不通問題在哪裏
後來發現,原來slave已經默認開啓,要先關閉再開啓
執行 slave stop;
再執行
mysql>change master to master_host='172.16.1.119',master_user='zone',master_password='123456', master_log_file='mysql-bin.000043' ,master_log_pos=355695;
而後
mysql> start slave;
查看是否成功唄
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.1.119
Master_User: zone
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000043
Read_Master_Log_Pos: 355695
Relay_Log_File: mysql_3306-relay-bin.000002
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000043
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: zone,zone_credits,zone_main,zone_mood
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: 355695
Relay_Log_Space: 414
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 193300
1 row in set (0.00 sec)
ERROR:
No query specified
真是折磨我很久。。。。。。學習能力太差了。。。。。。