国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

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

2024-07-24 12:53:18
字體:
供稿:網(wǎng)友

MySQL 讀寫分離

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

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

說明文檔: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)帶讀寫分離功能的MySQL類完整實(shí)例MySQL5.6 Replication主從復(fù)制(讀寫分離) 配置完整版MySQL的使用中實(shí)現(xiàn)讀寫分離的教程Yii實(shí)現(xiàn)MySQL多數(shù)據(jù)庫和讀寫分離實(shí)例分析Thinkphp實(shí)現(xiàn)MySQL讀寫分離操作示例通過mysql-proxy完成mysql讀寫分離使用PHP實(shí)現(xiàn)Mysql讀寫分離Ubuntu10下如何搭建MySQL Proxy讀寫分離探討MySQL主從同步、讀寫分離配置步驟mysql 讀寫分離(實(shí)戰(zhàn)篇)mysql 讀寫分離(基礎(chǔ)篇)
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 张家界市| 偏关县| 介休市| 蒙阴县| 酉阳| 永昌县| 崇礼县| 贡嘎县| 桑日县| 舒兰市| 磐石市| 玛沁县| 黄大仙区| 盐池县| 榆林市| 临高县| 洮南市| 鹤山市| 万源市| 杭州市| 樟树市| 彰化县| 右玉县| 云梦县| 舞钢市| 通渭县| 沁水县| 揭西县| 迁安市| 乡城县| 贵阳市| 新兴县| 太湖县| 平舆县| 襄城县| 汝阳县| 永昌县| 洪洞县| 娱乐| 琼海市| 株洲县|