文/A.Lang 於 2009/2/28 (alang<dot>hsu<at>gmail<dot>com) *轉載請註明原作者*
MySQL Replication - MySQL 資料庫抄寫。
為何要作Replication(抄寫)
- 報表(Reporting) - 對於需產出大量報表的資料庫而言,為不影響 Master DB 的效能,建議另外建置另一個專屬的報表資料庫。
- 資料安全 - 資料庫抄寫至 Slave DB,必要時可隨時關閉抄寫程序。對 Slave DB 作資料庫備份也可避免對 Master DB 的線上運作影響。
- 異地備份 - 對於分公司資料庫的複製或異地備份需求。
系統環境
Master DB)
Purpose: Production
IP address: 10.10.10.112
DB version: mysql-server-5.0.22-2.2.el5_1.1
Slave DB)
Purpose: Backup or Reporting
IP address: 10.10.10.134
DB version:
如何建置兩個資料庫的抄寫
新增一個資料庫用戶用以執行抄寫
這個用戶是在 Master DB,用來讓 Slave DB 連接用,其權限僅需要開啟 REPLICATION SLAVE,例如新增一個用戶為 repl,密碼為 replpass。
在 Master DB 執行下列 SQL statements:
reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)Callstack:
at User:Alang/Linux_&_UNIX_工作筆記/MySQL_DBA_筆記/MySQL_Replication
MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException: reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown.
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptVar expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptVar.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Evaluate (MindTouch.Deki.Script.Expr.DekiScriptAccess expr, DekiScriptExpressionEvaluationState state, Boolean evaluateProperties) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptAccess expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptAccess.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptCall expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptCall.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptSequence expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptSequence.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptReturnScope expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
你可以對每一個 Slave DB 設定不同連接帳號,也可以用同一個帳號。
Tip:
上述的新增帳戶方式是以 Slave DB 的 IP 來限制連接的來源,如果實際的操作環境有使用 domain 也可以改成 domain name 方式來作,詳細方法請參考官方的線上手冊。