濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > MySQL 讀寫(xiě)分離實(shí)例詳解

MySQL 讀寫(xiě)分離實(shí)例詳解

熱門(mén)標(biāo)簽:外呼系統(tǒng)怎樣才能不封號(hào) 西藏地圖標(biāo)注改進(jìn)點(diǎn) 地圖標(biāo)注什么軟件好用 如何辦理400客服電話 地圖標(biāo)注專員入駐 地圖標(biāo)注百度競(jìng)價(jià) 神行者百貨商場(chǎng)地圖標(biāo)注 安陽(yáng)手機(jī)自動(dòng)外呼系統(tǒng)原理是什么 外呼系統(tǒng)線路經(jīng)常出問(wèn)題嗎

MySQL 讀寫(xiě)分離

MySQL讀寫(xiě)分離又一好辦法 使用 com.mysql.jdbc.ReplicationDriver

在用過(guò)Amoeba 和 Cobar,還有dbware 等讀寫(xiě)分離組件后,今天我的一個(gè)好朋友跟我講,MySQL自身的也是可以讀寫(xiě)分離的,因?yàn)樗麄兲峁┝艘粋€(gè)新的驅(qū)動(dòng),叫 com.mysql.jdbc.ReplicationDriver

說(shuō)明文檔:http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-replication-connection.html

 代碼例子:

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Properties;
 
import com.mysql.jdbc.ReplicationDriver;
 
public class ReplicationDriverDemo {
 
 public static void main(String[] args) throws Exception {
  ReplicationDriver driver = new ReplicationDriver();
 
  Properties props = new Properties();
 
  // We want this for failover on the slaves
  props.put("autoReconnect", "true");
 
  // We want to load balance between the slaves
  props.put("roundRobinLoadBalance", "true");
 
  props.put("user", "foo");
  props.put("password", "bar");
 
  //
  // Looks like a normal MySQL JDBC url, with a
  // comma-separated list of hosts, the first
  // being the 'master', the rest being any number
  // of slaves that the driver will load balance against
  //
 
  Connection conn =
    driver.connect("jdbc:mysql:replication://master,slave1,slave2,slave3/test",
      props);
 
  //
  // Perform read/write work on the master
  // by setting the read-only flag to "false"
  //
 
  conn.setReadOnly(false);
  conn.setAutoCommit(false);
  conn.createStatement().executeUpdate("UPDATE some_table ....");
  conn.commit();
 
  //
  // Now, do a query from a slave, the driver automatically picks one
  // from the list
  //
 
  conn.setReadOnly(true);
 
  ResultSet rs =
   conn.createStatement().executeQuery("SELECT a,b FROM alt_table");
 
   .......
 }
}

感謝閱讀,希望能幫助到大家,謝謝大對(duì)本站的支持!

您可能感興趣的文章:
  • php實(shí)現(xiàn)帶讀寫(xiě)分離功能的MySQL類完整實(shí)例
  • MySQL5.6 Replication主從復(fù)制(讀寫(xiě)分離) 配置完整版
  • MySQL的使用中實(shí)現(xiàn)讀寫(xiě)分離的教程
  • Yii實(shí)現(xiàn)MySQL多數(shù)據(jù)庫(kù)和讀寫(xiě)分離實(shí)例分析
  • Thinkphp實(shí)現(xiàn)MySQL讀寫(xiě)分離操作示例
  • 通過(guò)mysql-proxy完成mysql讀寫(xiě)分離
  • 使用PHP實(shí)現(xiàn)Mysql讀寫(xiě)分離
  • Ubuntu10下如何搭建MySQL Proxy讀寫(xiě)分離探討
  • MySQL主從同步、讀寫(xiě)分離配置步驟
  • mysql 讀寫(xiě)分離(實(shí)戰(zhàn)篇)
  • mysql 讀寫(xiě)分離(基礎(chǔ)篇)

標(biāo)簽:阜陽(yáng) 酒泉 AXB 貴港 衡水 張掖 雞西 萍鄉(xiāng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《MySQL 讀寫(xiě)分離實(shí)例詳解》,本文關(guān)鍵詞  MySQL,讀寫(xiě),分離,實(shí)例,詳解,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《MySQL 讀寫(xiě)分離實(shí)例詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于MySQL 讀寫(xiě)分離實(shí)例詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    蓝田县| 中阳县| 辽阳市| 固安县| 奈曼旗| 称多县| 叙永县| 堆龙德庆县| 温宿县| 湘潭市| 沧州市| 美姑县| 肃宁县| 郯城县| 横峰县| 天峨县| 宁晋县| 巩义市| 渭南市| 司法| 新民市| 渑池县| 黑山县| 同德县| 陕西省| 波密县| 商丘市| 桃园市| 邳州市| 合山市| 青神县| 三门峡市| 庐江县| 射阳县| 洱源县| 南平市| 太白县| 元氏县| 龙泉市| 潢川县| 株洲县|