mysql主從,主主備份原理及實踐

學一點 mysql 雙機異地熱備份----快速理解mysql主從,主主備份原理及實踐html

簡介:

感謝你們在上一篇 學一點Git--20分鐘git快速上手 裏的踊躍發言。這裏再次分享乾貨, 簡單介紹mysql雙機,多機異地熱備簡單原理實戰。mysql

雙機熱備的概念簡單說一下,就是要保持兩個數據庫的狀態自動同步。對任何一個數據庫的操做都自動應用到另一個數據庫,始終保持兩個數據庫數據一致。 這樣作的好處多。 1. 能夠作災備,其中一個壞了能夠切換到另外一個。 2. 能夠作負載均衡,能夠將請求分攤到其中任何一臺上,提升網站吞吐量。  對於異地熱備,尤爲適合災備。廢話很少說了。咱們直接進入主題。 咱們會主要介紹兩部份內容:ios

1、mysql 備份工做原理git

2、 備份實戰sql

我使用的是mysql 5.5.34,shell

1、 mysql 備份工做原理

簡單的說就是把 一個服務器上執行過的sql語句在別的服務器上也重複執行一遍, 這樣只要兩個數據庫的初態是同樣的,那麼它們就能一直同步。數據庫

固然這種複製和重複都是mysql自動實現的,咱們只須要配置便可。安全

咱們進一步詳細介紹原理的細節, 這有一張圖:服務器

上圖中有兩個服務器, 演示了從一個主服務器(master) 把數據同步到從服務器(slave)的過程。負載均衡

這是一個主-從複製的例子。 主-主互相複製只是把上面的例子反過來再作一遍。 因此咱們以這個例子介紹原理。

對於一個mysql服務器, 通常有兩個線程來負責複製和被複制。當開啓複製以後。

1. 做爲主服務器Master,  會把本身的每一次改動都記錄到 二進制日誌 Binarylog 中。 (從服務器會負責來讀取這個log, 而後在本身那裏再執行一遍。)

2. 做爲從服務器Slave, 會用master上的帳號登錄到 master上, 讀取master的Binarylog,  寫入到本身的中繼日誌 Relaylog, 而後本身的sql線程會負責讀取這個中繼日誌,並執行一遍。  到這裏主服務器上的更改就同步到從服務器上了。

在mysql上能夠查看當前服務器的主,從狀態。 其實就是當前服務器的 Binary(做爲主服務器角色)狀態和位置。 以及其RelayLog(做爲從服務器)的複製進度。

例如咱們在主服務器上查看主狀態:

 

mysql> show master status\G
*************************** 1. row ***************************
            File: mysql-bin.000014
        Position: 107
    Binlog_Do_DB: 
Binlog_Ignore_DB: mysql,information_schema,performance_schema,amh
1 row in set (0.00 sec)

稍微解釋一下這幾行的意思:

1. 第一行代表 當前正在記錄的 binarylog文件名是: mysql-bin.000014.

咱們能夠在mysql數據目錄下,找到這個文件:

 

2.  第二行, 107. 表示當前的文件偏移量, 就是寫入在mysql-bin.000014 文件的記錄位置。

這兩點就構成了 主服務器的狀態。  配置從服務器的時候,須要用到這兩個值。 告訴從服務器從哪讀取主服務器的數據。 (從服務器會登陸以後,找到這個日誌文件,並從這個偏移量以後開始複製。)

3. 第三行,和第四行,表示須要記錄的數據庫和須要忽略的數據庫。 只有須要記錄的數據庫,其變化纔會被寫入到mysql-bin.000014日誌文件中。  後面會再次介紹這兩個參數。

咱們還能夠在從服務器上,查看從服務器的複製狀態。

 

咱們仍是來重點解釋途中的紅圈的部分:

1.  Master_host 指的是 主服務器的地址。 

2. Master_user 指的是主服務器上用來複制的用戶。  從服務器會用此帳號來登陸主服務。進行復制。

3. Master_log_file 就是前面提到的, 主服務器上的日誌文件名.

4. Read_Master_log_pos 就是前面提到的主服務器的日誌記錄位置, 從服務器根據這兩個條件來選擇複製的文件和位置。

5. Slave_IO_Running:  指的就是從服務器上負責讀取主服務器的線程工做狀態。 從服務器用這個專門的線程連接到主服務器上,並把日誌拷貝回來。

6. Slave_SQL_Running: 指的就是專門執行sql的線程。 它負責把複製回來的Relaylog執行到本身的數據庫中。 這兩個參數必須都爲Yes 才代表複製在正常工做。

其餘的參數以後再介紹。

2、mysql 雙機熱備實戰

瞭解了上面的原理以後, 咱們來實戰。 這裏有兩個重點, 要想同步數據庫狀態, 須要相同的初態,而後配置同步纔有意義。 固然你能夠不要初態,這是你的自由。 咱們這裏從頭開始配置一遍。

 

咱們先以A服務器爲起點,  配置它的數據庫同步到B。  這就是主-從複製了。 以後再反過來作一次,就能夠互相備份了。

1, 第一步,

在A上面建立專門用於備份的 用戶:

 

grant replication slave on *.* to 'repl_user'@'192.***.***.***' identified by 'hj34$%&mnkb';

上面把ip地址換成B機器的ip地址。 只容許B登陸。安全。

用戶名爲: repl_user

密碼爲: hj34$********nkb

這個等會在B上面要用。

2. 開啓主服務器的 binarylog。

不少服務器是默認開啓的,咱們這裏檢查一下:

打開 /etc/my.cnf

 

我來解釋一下紅框中的配置:

前面三行, 你可能已經有了。

binlog-do-db 用來表示,只把哪些數據庫的改動記錄到binary日誌中。 能夠寫上關注hello數據庫。 可是我把它註釋掉了。 只是展現一下。 能夠寫多行,表示關注多個數據庫。

binlog-ignore-db 表示,須要忽略哪些數據庫。我這裏忽略了其餘的4個數據庫。

後面兩個用於在 雙主(多主循環)互相備份。 由於每臺數據庫服務器均可能在同一個表中插入數據,若是表有一個自動增加的主鍵,那麼就會在多服務器上出現主鍵衝突。  解決這個問題的辦法就是讓每一個數據庫的自增主鍵不連續。  上圖說是, 我假設須要未來可能須要10臺服務器作備份, 因此auto-increment-increment 設爲10.   而 auto-increment-offset=1 表示這臺服務器的序號。 從1開始, 不超過auto-increment-increment。

這樣作以後, 我在這臺服務器上插入的第一個id就是 1, 第二行的id就是 11了, 而不是2.

(同理,在第二臺服務器上插入的第一個id就是2, 第二行就是12, 這個後面再介紹) 這樣就不會出現主鍵衝突了。 後面咱們會演示這個id的效果。

3.  獲取主服務器狀態, 和同步初態。

假設我如今有這些數據庫在A上面。

若是你是全新安裝的, 那麼不須要同步初態,直接跳過這一步,到後面直接查看主服務器狀態。

這裏咱們假設有一個 hello 數據庫做爲初態。

 

先鎖定 hello數據庫:

FLUSH TABLES WITH READ LOCK;

 

而後導出數據:

我這裏只須要導出hello數據庫, 若是你有多個數據庫做爲初態的話, 須要導出全部這些數據庫:

 

而後查看A服務器的binary日誌位置:

記住這個文件名和 位置, 等會在從服務器上會用到。

 

主服務器已經作完了, 能夠解除鎖定了:

 

4.  設置從服務器 B 須要複製的數據庫

打開從服務器 B 的 /etc/my.cnf 文件:

 

解釋一下上面的內容。

server-id 必須保證每一個服務器不同。 這可能和循環同步有關。 防止進入死循環。

replicate-do-db 能夠指定須要複製的數據庫, 我這裏注掉了。 演示一下。

replicate-ignore-db 複製時須要排除的數據庫, 我使用了,這個。 除開系統的幾個數據庫以外,全部的數據庫都複製。

relay_log 中繼日誌的名字。 前面說到了, 複製線程須要先把遠程的變化拷貝到這個中繼日誌中, 在執行。

log-slave-updates 意思是,中繼日誌執行以後,這些變化是否須要計入本身的binarylog。 當你的B服務器須要做爲另一個服務器的主服務器的時候須要打開。  就是雙主互相備份,或者多主循環備份。 咱們這裏須要, 因此打開。

保存, 重啓mysql。

5. 導入初態, 開始同步。

把剛纔從A服務器上導出的 hello.sql 導入到 B的hello數據庫中, 若是B如今沒有hello數據庫,請先建立一個, 而後再導入:

建立數據庫:

mysql> create database hello default charset utf8;

把hello.sql 上傳到B上, 而後導入:

 

若是你剛纔導出了多個數據庫, 須要把他們都一一上傳導入。

開啓同步, 在B服務器上執行:

CHANGE MASTER TO 
       MASTER_HOST='192.***.***.***', 
       MASTER_USER='repl_user', 
       MASTER_PASSWORD='hj3****', 
       MASTER_LOG_FILE='mysql-bin.000004', 
       MASTER_LOG_POS=7145;

 

上面幾個參數我就不解釋了。 前面說過了。

重啓mysql,  而後查看slave線程開啓了沒:

 

注意圖中的紅框, 兩個都是Yes, 說明開啓成功。

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

若是其中一個是No, 那就說明不成功。須要查看mysql的錯誤日誌。 我在第一次作的時候就遇到這個問題。有時候密碼填錯了, 有時候防火牆的3306沒有打開。ip地址不對,等等。 都會致使失敗。

咱們看錯誤日誌: mysql的錯誤日誌通常在:

 

文件名應該是你的機器名, 我這裏叫作host1.err 你換成你本身的。

到這裏主-從複製已經打開了。 咱們先來實驗一下。

咱們在A的數據庫裏面去 添加數據:

 

我在A的 hello數據庫的test表中 連續插入了3條數據,  注意看他們的自增加id, 分別是1,11,21.  知道這是爲何嗎。 前面已經說過了,不懂再回去看。

咱們去看一下B數據庫有沒有這三條數據:

打開B的數據庫:

 

發現已經在這了。 這裏效果不直觀。

此時不要在B中修改數據。 咱們接着配置從B到A的複製。  若是你只須要主從複製的話, 到這裏就結束了。後面能夠不看了。 全部A中的修改都能自動同步到B, 可是對B的修改卻不能同步到A。 由於是單向的。 若是須要雙向同步的話,須要再作一次從B到A的複製。

基本跟上面同樣:咱們簡單一點介紹:

1. 在B中建立用戶;

2. 打開 /etc/my.cnf , 開啓B的binarylog:

 

注意紅框中所新添加的部分。

3. 咱們不須要導出B的初態了,由於它剛剛纔從A導過來。  直接記住它的master日誌狀態:

 

記住這兩個數值,等會在A上面要用。

B服務器就設置完了。

4. 登陸到A 服務器。 開啓中繼:

 

注意框中心添加的部分, 不解釋了。

5. 啓動同步:

 

上面的ip地址是B的ip地址, 由於A把B當作master了。 不解釋了。

而後重啓mysql服務。

而後查看,slave狀態是否正常:

 

圖中出現了兩個No。

Slave_IO_Running: No

Slave_SQL_Running: No

說明slave沒有成功, 即,從B到A的同步沒有成功。 咱們去查看mysql錯誤日誌,前面說過位置:

 

找到  機器名.err 文件,打開看看:

 

看圖中的error信息。  說找不到中繼日誌文件。

這是由於咱們在配置A的中繼文件時改了中繼文件名,可是mysql沒有同步。解決辦法很簡單。

 

先停掉mysql服務。  找到這三個文件,把他們刪掉。 必定要先停掉mysql服務。否則仍是不成功。你須要重啓一下機器了。 或者手動kill mysqld。

好了, 啓動mysql以後。 咱們在來檢查一下slave狀態:

 

注意圖中兩個大大的Yes。  哈哈。

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

證實從B到A的複製也成功了。

此時咱們去B服務器中插入幾條數據試試:

 

我在B中插入了兩條數據。 注意看他們的id。  不解釋。

而後咱們,登陸去A中看看,A數據庫變了沒。

 

能夠看到已經自動同步到A了。

至此, AB雙主互相熱備就介紹完了。

原理其實很簡單,是否是。

理解了這個原理, 多機循環互備就簡單了。這裏就再也不展開了。

花了一天時間寫這個博客,你們要頂啊。

3、mysql主從複製(另外一方法,超簡單)

怎麼安裝mysql數據庫,這裏不說了,只說它的主從複製,步驟以下:

一、主從服務器分別做如下操做
  1.一、版本一致
  1.二、初始化表,並在後臺啓動mysql
  1.三、修改root的密碼

二、修改主服務器master:
   #vi /etc/my.cnf
       [mysqld]
       log-bin=mysql-bin   //[必須]啓用二進制日誌
       server-id=222      //[必須]服務器惟一ID,默認是1,通常取IP最後一段

三、修改從服務器slave:
   #vi /etc/my.cnf
       [mysqld]
       log-bin=mysql-bin   //[不是必須]啓用二進制日誌
       server-id=226      //[必須]服務器惟一ID,默認是1,通常取IP最後一段

四、重啓兩臺服務器的mysql
   /etc/init.d/mysql restart

五、在主服務器上創建賬戶並受權slave:
   #/usr/local/mysql/bin/mysql -uroot -pmttang   
   mysql>GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'q123456'; //通常不用root賬號,“%”表示全部客戶端均可能連,只要賬號,密碼正確,此處可用具體客戶端IP代替,如192.168.145.226,增強安全。

六、登陸主服務器的mysql,查詢master的狀態
   mysql>show master status;
   +------------------+----------+--------------+------------------+
   | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
   +------------------+----------+--------------+------------------+
   | mysql-bin.000004 |      308 |              |                  |
   +------------------+----------+--------------+------------------+
   1 row in set (0.00 sec)
   注:執行完此步驟後不要再操做主服務器MYSQL,防止主服務器狀態值變化

七、配置從服務器Slave:
   mysql>change master to master_host='192.168.145.222',master_user='mysync',master_password='q123456',
         master_log_file='mysql-bin.000004',master_log_pos=308;   //注意不要斷開,308數字先後無單引號。

   Mysql>start slave;    //啓動從服務器複製功能

八、檢查從服務器複製功能狀態:

   mysql> show slave status\G

   *************************** 1. row ***************************

              Slave_IO_State: Waiting for master to send event
              Master_Host: 192.168.2.222  //主服務器地址
              Master_User: mysync   //受權賬戶名,儘可能避免使用root
              Master_Port: 3306    //數據庫端口,部分版本沒有此行
              Connect_Retry: 60
              Master_Log_File: mysql-bin.000004
              Read_Master_Log_Pos: 600     //#同步讀取二進制日誌的位置,大於等於Exec_Master_Log_Pos
              Relay_Log_File: ddte-relay-bin.000003
              Relay_Log_Pos: 251
              Relay_Master_Log_File: mysql-bin.000004
              Slave_IO_Running: Yes    //此狀態必須YES
              Slave_SQL_Running: Yes     //此狀態必須YES
                    ......

注:Slave_IO及Slave_SQL進程必須正常運行,即YES狀態,不然都是錯誤的狀態(如:其中一個NO均屬錯誤)。

以上操做過程,主從服務器配置完成。
  
九、主從服務器測試:

主服務器Mysql,創建數據庫,並在這個庫中建表插入一條數據:

  mysql> create database hi_db;
  Query OK, 1 row affected (0.00 sec)

  mysql> use hi_db;
  Database changed

  mysql>  create table hi_tb(id int(3),name char(10));
  Query OK, 0 rows affected (0.00 sec)
 
  mysql> insert into hi_tb values(001,'bobu');
  Query OK, 1 row affected (0.00 sec)

  mysql> show databases;
   +--------------------+
   | Database           |
   +--------------------+
   | information_schema |
   | hi_db                |
   | mysql                |
   | test                 |
   +--------------------+
   4 rows in set (0.00 sec)

從服務器Mysql查詢:

   mysql> show databases;

   +--------------------+
   | Database               |
   +--------------------+
   | information_schema |
   | hi_db                 |       //I'M here,你們看到了吧
   | mysql                 |
   | test          |

   +--------------------+
   4 rows in set (0.00 sec)

   mysql> use hi_db
   Database changed
   mysql> select * from hi_tb;           //查看主服務器上新增的具體數據
   +------+------+
   | id   | name |
   +------+------+
   |    1 | bobu |
   +------+------+
   1 row in set (0.00 sec)

十、完成:

    編寫一shell腳本,用nagios監控slave的兩個yes(Slave_IO及Slave_SQL進程),如發現只有一個或零個yes,就代表主從有問題了,發短信警報吧。

操做後記得執行:

mysql>flush privileges;  保存

操做:

show master status; //主庫狀態

stop slave;    //啓動從服務器複製功能

reset slave;

change master to master_host='xxx.xxx.xx.xx',

master_user='repl_user',

master_password='123456',

master_log_file='master-bin.000001',

master_log_pos=1044;

start slave;    //啓動從服務器複製功能

flush privileges;  保存

show slave status\G //查看Slave_IO_Running和Slave_SQL_Running爲yes

出現問題時,刪除

/var/lib/mysql

rm -rf mysql-relay-bin*  slave-bin*  relay-log* master.info

show master status; //主庫狀態

stop slave;    //啓動從服務器複製功能

reset slave;

change master to master_host='192.168.11.1',

master_user='repl_user',

master_password='123456',

master_log_file='master-bin.000001',

master_log_pos=1044;

start slave;    //啓動從服務器複製功能

flush privileges;  保存

show slave status\G; //查看Slave_IO_Running和Slave_SQL_Running爲yes

出現問題時,刪除

/var/lib/mysql

rm -rf mysql-relay-bin*  slave-bin*  relay-log* master.info

 

備註:

4、單實例(配置)

======================單實例===================================

1.單實例(主庫my.cnf)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
log-bin=master-bin
log-bin-index=master-bin.index
server-id=1

read-only=0
#binlog-do-db=hello
binlog-ignore-db=mysql
binlog-ignore-db=infomation_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=test
auto-increment-increment = 1
auto-increment-offset = 1

expire_logs_day=7

log-bin-trust-function-creators=1

innodb_buffer_pool_size = 6G
max_connections=3000
innodb_flush_log_at_trx_commit=2
thread_cache_size=512
innodb_log_file_size=536870912
innodb_log_buffer_size=67108864
basedir =/usr/local/mysql
binlog_format=MIXED

#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 

2.單實例從庫(my.cnf)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
server-id=2
log-bin=slave-bin
log-bin-index=slave-bin.index
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin

expire_logs_day=7

#replicate-do-db = hello
replicate-ignore-db = mysql
replicate-ignore-db = infomation_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = test
relay_log=mysql-relay-bin
log-slave-updates = ON

log-bin-trust-function-creators=1

innodb_buffer_pool_size = 6G
max_connections=3000
innodb_flush_log_at_trx_commit=2
thread_cache_size=512
innodb_log_file_size=536870912
innodb_log_buffer_size=67108864
basedir =/usr/local/mysql
binlog_format=MIXED

#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
"/etc/my.cnf" 48L, 1422C

5、雙實例(配置)

=========================雙實例==================================

1.雙實例(主庫myAndroid.cnf)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
log-bin=/var/lib/mysql-Android/master-bin
log-bin-index=/var/lib/mysql-Android/master-bin.index
server-id=1

read-only=0
#binlog-do-db=hello
binlog-ignore-db=mysql
binlog-ignore-db=infomation_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=test
auto-increment-increment = 1
auto-increment-offset = 1

expire_logs_day=7

log-bin-trust-function-creators=1

innodb_buffer_pool_size = 6G
max_connections=3000
innodb_flush_log_at_trx_commit=2
thread_cache_size=512
innodb_log_file_size=536870912
innodb_log_buffer_size=67108864
basedir =/usr/local/mysql

#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

port = 3456
datadir=/var/lib/mysql-Android
socket=/var/lib/mysql-Android/mysql.sock
pid-file = /var/lib/mysql-Android/mysql.pid  

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysql-Android.log
pid-file=/var/run/mysqld/mysql-Android.pid


2.雙實例(主庫myIOS.cnf)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
log-bin=/var/lib/mysql-IOS/master-bin
log-bin-index=/var/lib/mysql-IOS/master-bin.index
server-id=1

read-only=0
#binlog-do-db=hello
binlog-ignore-db=mysql
binlog-ignore-db=infomation_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=test
auto-increment-increment = 1
auto-increment-offset = 1

expire_logs_day=7

log-bin-trust-function-creators=1

innodb_buffer_pool_size = 6G
max_connections=3000
innodb_flush_log_at_trx_commit=2
thread_cache_size=512
innodb_log_file_size=536870912
innodb_log_buffer_size=67108864
basedir =/usr/local/mysql

#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

port = 8061
datadir=/var/lib/mysql-IOS
socket=/var/lib/mysql-IOS/mysql.sock
pid-file = /var/lib/mysql-IOS/mysql.pid  

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysql-IOS.log
pid-file=/var/run/mysqld/mysql-IOS.pid
 

3.雙實例從庫(myAndroid.cnf)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
server-id=2
log-bin=/var/lib/mysql-Android/slave-bin
log-bin-index=/var/lib/mysql-Android/slave-bin.index
relay-log-index=/var/lib/mysql-Android/slave-relay-bin.index
relay-log=/var/lib/mysql-Android/slave-relay-bin

expire_logs_day=7

#replicate-do-db = hello
replicate-ignore-db = mysql
replicate-ignore-db = infomation_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = test
relay_log=mysql-relay-bin
log-slave-updates = ON

log-bin-trust-function-creators=1

innodb_buffer_pool_size = 6G
max_connections=3000
innodb_flush_log_at_trx_commit=2
thread_cache_size=512
innodb_log_file_size=536870912
innodb_log_buffer_size=67108864
basedir =/usr/local/mysql

#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

port = 3456
datadir=/var/lib/mysql-Android
socket=/var/lib/mysql-Android/mysql.sock
pid-file = /var/lib/mysql-Android/mysql.pid 

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysql-Android.log
pid-file=/var/run/mysqld/mysql-Android.pid

4.雙實例(從庫myIOS.cnf)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
server-id=2
log-bin=/var/lib/mysql-IOS/slave-bin
log-bin-index=/var/lib/mysql-IOS/slave-bin.index
relay-log-index=/var/lib/mysql-IOS/slave-relay-bin.index
relay-log=/var/lib/mysql-IOS/slave-relay-bin

expire_logs_day=7

#replicate-do-db = hello
replicate-ignore-db = mysql
replicate-ignore-db = infomation_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = test
relay_log=mysql-relay-bin
log-slave-updates = ON

log-bin-trust-function-creators=1

innodb_buffer_pool_size = 6G
max_connections=3000
innodb_flush_log_at_trx_commit=2
thread_cache_size=512
innodb_log_file_size=536870912
innodb_log_buffer_size=67108864
basedir =/usr/local/mysql

#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

port = 8061
datadir=/var/lib/mysql-IOS
socket=/var/lib/mysql-IOS/mysql.sock
pid-file = /var/lib/mysql-IOS/mysql.pid  

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe] log-error=/var/log/mysql-IOS.log pid-file=/var/run/mysqld/mysql-IOS.pid

相關文章
相關標籤/搜索