1. 程式人生 > >mycat1.6實現單庫分表#

mycat1.6實現單庫分表#

1,下載mycat1.6(http://dl.mycat.io/1.6-RELEASE/ “選擇win版本 第6個檔案就是”)
2,把server.xml,rule.xml,schema.xml,wrapper.conf替換成如下配置
3,在mysql建立 庫名為 testdb2 然後執行 文章下方提供的sql
4,重啟mycat
5,用Navicat登入mycat 執行3個INSERT INSERT INTO t_order(id,name,t_user_id) VALUES(1,'dd1',1); ,觀察分表效果
dome github https://github.com/gyn781369549/MyCat1.6dome


mycat\conf 下的server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
    - you may not use this file except in compliance with the License. - You 
    may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
    - - Unless required by applicable law or agreed to in writing, software - 
    distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
    License for the specific language governing permissions and - limitations 
    under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd"> <mycat:server xmlns:mycat="http://io.mycat/"> <system> <property name="useSqlStat">0</property> <!-- 1為開啟實時統計、0為關閉 --> <property name="useGlobleTableCheck">0</property> <!-- 1為開啟全加班一致性檢測、0為關閉 --> <property
name="sequnceHandlerType">
2</property> <!-- <property name="useCompression">1</property>--> <!--1為開啟mysql壓縮協議--> <!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--設定模擬的MySQL版本號--> <!-- <property name="processorBufferChunk">40960</property> --> <!-- <property name="processors">1</property> <property name="processorExecutor">32</property> --> <!--預設為type 0: DirectByteBufferPool | type 1 ByteBufferArena--> <property name="processorBufferPoolType">0</property> <!--預設是65535 64K 用於sql解析時最大文字長度 --> <!--<property name="maxStringLiteralLength">65535</property>--> <!--<property name="sequnceHandlerType">0</property>--> <!--<property name="backSocketNoDelay">1</property>--> <!--<property name="frontSocketNoDelay">1</property>--> <!--<property name="processorExecutor">16</property>--> <!-- <property name="serverPort">8066</property> <property name="managerPort">9066</property> <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property> <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> --> <!--分散式事務開關,0為不過濾分散式事務,1為過濾分散式事務(如果分散式事務內只涉及全域性表,則不過濾),2為不過濾分散式事務,但是記錄分散式事務日誌--> <property name="handleDistributedTransactions">0</property> <!-- off heap for merge/order/group/limit 1開啟 0關閉 --> <property name="useOffHeapForMerge">1</property> <!-- 單位為m --> <property name="memoryPageSize">1m</property> <!-- 單位為k --> <property name="spillsFileBufferSize">1k</property> <property name="useStreamOutput">0</property> <!-- 單位為m --> <property name="systemReserveMemorySize">384m</property> <!--是否採用zookeeper協調切換 --> <property name="useZKSwitch">false</property> </system> <!-- 全域性SQL防火牆設定 --> <!-- <firewall> <whitehost> <host host="127.0.0.1" user="mycat"/> <host host="127.0.0.2" user="mycat"/> </whitehost> <blacklist check="false"> </blacklist> </firewall> --> <!--mycat 使用者名稱--> <user name="root"> <!--mycat 密碼--> <property name="password">root</property> <property name="schemas">TESTDB</property> <!--是否只讀--> <property name="readOnly">false</property> <!-- 表級 DML 許可權設定 <privileges check="false"> <schema name="TESTDB" dml="0110" > <table name="dn1" dml="1111"></table> </schema> </privileges> --> </user> <user name="user"> <property name="password">user</property> <property name="schemas">TESTDB</property> <property name="readOnly">true</property> </user> </mycat:server>

mycat\conf 下的rule.xml 分表規則 按id 平均分

<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
    - you may not use this file except in compliance with the License. - You 
    may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
    - - Unless required by applicable law or agreed to in writing, software - 
    distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
    License for the specific language governing permissions and - limitations 
    under the License. -->
<!DOCTYPE mycat:rule SYSTEM "rule.dtd">
<mycat:rule xmlns:mycat="http://io.mycat/">

    <tableRule name="mod-long"> 
        <rule> 
            <!--按照id分表-->
            <columns>id</columns> 
            <algorithm>mod-long</algorithm> 
        </rule> 

    </tableRule> 

    <function name="mod-long" class="io.mycat.route.function.PartitionByMod">
            <!--與表數量對應 平均分配-->
             <property name="count">3</property>
    </function>

</mycat:rule>

mycat\conf 下的schema.xml schema 是配置的mycat邏輯庫 與資料庫表名要對應

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">

    <!-- name="TESTDB"是在server.xml中配置<property name="schemas">TESTDB</property>-->
    <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100"  > 
        <!-- 與mysql資料庫中的表名對應 subTables="t_order$1-3"是配置分表的 對應mysql t_order1,t_order2,t_order3表的
        primaryKey="id" 是主鍵id
        -->
        <table name="t_order" primaryKey="id" autoIncrement="true"  subTables="t_order$1-3"  dataNode="dn1" rule="mod-long"  >

        </table>
        <table name="t_user" primaryKey="id" autoIncrement="true"  dataNode="dn1" />    



    </schema> 
    <!--配置mysql資料庫testdb2  mycat邏輯庫名為 dn1-->
    <dataNode name="dn1" dataHost="localhost1" database="testdb2" /> 
    <!--配置資料型別 balance="0"讀寫不分離 -->
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"  writeType="0" dbType="mysql"  dbDriver="native" switchType="1" slaveThreshold="100"> 
            <!--心跳包 -->
            <heartbeat>select root()</heartbeat> 
            <!--配置mysql資料 賬戶密碼 -->
            <writeHost host="hostM1" url="localhost:3306" user="root" password="pwd" /> 
    </dataHost>
</mycat:schema>

mycat\conf 下的 wrapper.conf wrapper.java.command=配置java

#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=D:\Java\jdk1.7.0_67\bin\java.exe
wrapper.working.dir=..

# Java Main class.  This class must implement the WrapperListener interface
#  or guarantee that the WrapperManager class is initialized.  Helper
#  classes are provided to do this for you.  See the Integration section
#  of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
set.default.REPO_DIR=lib
set.APP_BASE=.

# Java Classpath (include wrapper.jar)  Add class path elements as
#  needed starting from 1
wrapper.java.classpath.1=lib/wrapper.jar
wrapper.java.classpath.2=conf
wrapper.java.classpath.3=%REPO_DIR%/*

# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=lib

# Java Additional Parameters
#wrapper.java.additional.1=
wrapper.java.additional.1=-DMYCAT_HOME=.
wrapper.java.additional.2=-server
wrapper.java.additional.3=-XX:MaxPermSize=64M
wrapper.java.additional.4=-XX:+AggressiveOpts
wrapper.java.additional.5=-XX:MaxDirectMemorySize=2G
wrapper.java.additional.6=-Dcom.sun.management.jmxremote
wrapper.java.additional.7=-Dcom.sun.management.jmxremote.port=1984
wrapper.java.additional.8=-Dcom.sun.management.jmxremote.authenticate=false
wrapper.java.additional.9=-Dcom.sun.management.jmxremote.ssl=false
wrapper.java.additional.10=-Xmx4G
wrapper.java.additional.11=-Xms1G

# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3

# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64

# Application parameters.  Add parameters as needed starting from 1
wrapper.app.parameter.1=io.mycat.MycatStartup
wrapper.app.parameter.2=start

#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console.  (See docs for formats)
wrapper.console.format=PM

# Log Level for console output.  (See docs for log levels)
wrapper.console.loglevel=INFO

# Log file to use for wrapper output logging.
wrapper.logfile=logs/wrapper.log

# Format of output for the log file.  (See docs for formats)
wrapper.logfile.format=LPTM

# Log Level for log file output.  (See docs for log levels)
wrapper.logfile.loglevel=INFO

# Maximum size that the log file will be allowed to grow to before
#  the log is rolled. Size is specified in bytes.  The default value
#  of 0, disables log rolling.  May abbreviate with the 'k' (kb) or
#  'm' (mb) suffix.  For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0

# Maximum number of rolled log files which will be allowed before old
#  files are deleted.  The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0

# Log Level for sys/event log output.  (See docs for log levels)
wrapper.syslog.loglevel=NONE

#********************************************************************
# Wrapper Windows Properties
#********************************************************************
# Title to use when running as a console
wrapper.console.title=Mycat-server

#********************************************************************
# Wrapper Windows NT/2000/XP Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
#  using this configuration file has been installed as a service.
#  Please uninstall the service before modifying this section.  The
#  service can then be reinstalled.

# Name of the service
wrapper.ntservice.name=mycat

# Display name of the service
wrapper.ntservice.displayname=Mycat-server

# Description of the service
wrapper.ntservice.description=The project of Mycat-server

# Service dependencies.  Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=

# Mode in which the service is installed.  AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START

# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false

wrapper.ping.timeout=120
configuration.directory.in.classpath.first=conf

新建資料名為 testdb2 ,這是庫中所需表

DROP TABLE t_user;
DROP TABLE t_order1;
DROP TABLE t_order2;
DROP TABLE t_order3;
CREATE TABLE `t_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
CREATE TABLE `t_order1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `t_user_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
CREATE TABLE `t_order2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `t_user_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
CREATE TABLE `t_order3` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `t_user_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

由於1.6已經是release,現有的1.6分支當作1.6.5開發,導致無法修改,因此使用分表只能用替換class或者jar的方式:
替換jar:lib目錄下mycat-server:(基於1.6.5開發板)http://songwie.com/attached/mycat/Mycat-server-1.6.5-DEV.jar

java程式連線mycat,與連線mysql相同,可以直接用Navicat直接連mycat與連線mysql一樣,mycat預設埠8066

datasource.url=jdbc:mysql://localhost:8066/TESTDB?useUnicode=true&characterEncoding=utf-8

相關推薦

mycat1.6實現

mycat1.6實現單庫分表   1,下載mycat1.6(http://dl.mycat.io/1.6-RELEASE/ “選擇win版本 第6個檔案就是”)  2,把server.xml,rule.xml,schema.xml,wrapper.conf替換成

mycat1.6實現#

1,下載mycat1.6(http://dl.mycat.io/1.6-RELEASE/ “選擇win版本 第6個檔案就是”) 2,把server.xml,rule.xml,schema.xml,wrapper.conf替換成如下配置 3,在mysq

Mycat使用之MySQL及均分資料

使用Mycat做MySQL單庫分表。 一、Mycat安裝部署       安裝環境Linux 目前只有1.6.5版本支援單庫分表。 解壓後,修改配置檔案,在mycat/conf下 1.修改server.xml 設定user name,password及schemas,

MySQL數據區(一)(轉)

procedure 它的 找到 程序 鎖定 into 根據 服務器 har 面對當今大數據存儲,設想當mysql中一個表的總記錄超過1000W,會出現性能的大幅度下降嗎? 答案是肯定的,一個表的總記錄超過1000W,在操作系統層面檢索也是效率非常低的 解決方案: 目

數據設計

[1] datatable char* gic 一個數 code memcached {} 們的 具體來說就是數據庫有這樣的表account0account1account2account3 每個表假如說是存1萬個玩家sprintf(m_szSql,"UPDATE

實現MySQL分庫備份的腳本

linux 運維 linux運維工程師1)準備測試數據:通過寫腳本批量建庫建表並插入測試數據。[root@aliyun scripts]# cat ceshi.sh #/bin/bashPATH="/usr/local/mysql/bin:$PATH" #定

MySQL數據 分庫備份及批量恢復如何進行?

eight -- sim /bin/bash nbsp AR ble height l數據庫 腳本實現#!/bin/bashfor db_name in `mysql -e "show databases;"|sed 1d` do mkdir

工作筆記----數據

策略 uid 筆記 請求 批量 可用 均衡 方案設計 查詢 背景 用於存儲用戶簽到數據表中的數據量超過1500萬條,在進行查詢時相對緩慢決定對其進行分表。 步驟 a. 分析業務場景 該表的使用者為簽到用戶和運營人員。 簽到用戶進行簽到時在表中記錄的相關信息:uid、時間、

使用淘寶中介軟體cobar實現mysql分庫

cobar 編譯安裝配置筆記 https://github.com/alibaba/cobar windows下使用eclipse匯入cobar專案,eclipse File -> Import -> Git https://github.com/alibab

java自定義註解、mybatis 外掛 實現資料庫 分庫

一、自定義註解實現分庫 為什麼會有資料庫切庫一說 首先,許多專案都有主庫與從庫,有的主庫後面甚至會有很多個從庫,主從庫之間的通常同步也很快,這為資料庫切庫提供了一個基礎,因為可以去不同的資料庫查詢,得到相同的結果(如果不同的資料庫是完全不同的,這個不在我們這篇文章討論的範圍之內,那個屬於讓專

【筆記】MyCat1.6 實現 MySQL5.7 讀寫分離

本文不涉及分片、分庫、分表。僅僅作為入門。 前提 已搭好MySQL5.7主從複製環境,參考這裡 下載 Mycat下載地址 http://dl.mycat.io/ 我下載的是Mycat-server-1.6-RELEASE-20161028204710

數據和分庫 一點積累

這樣的 增刪改 個人 需要 用戶 har 減少 sha 怎麽辦 數據庫分庫分表一般是存儲了百萬級乃至千萬級條記錄的表。這樣的表過於龐大,導致數據庫在查詢和插入的時候耗時太長,性能低下,如果涉及聯合查詢的情況,性能會更加糟糕。分表和表分區的目的就是減少數據庫的負擔,提高數據庫

SpringBoot 2.0 整合sharding-jdbc中介軟體,實現資料分庫

一、水平分割 1、水平分庫 1)、概念: 以欄位為依據,按照一定策略,將一個庫中的資料拆分到多個庫中。 2)、結果 每個庫的結構都

你們要的MyCat實現MySQL分庫來了

❝ 藉助MyCat來實現MySQL的分庫分表落地,沒有實現過的,或者沒了解過的可以看看 ❞ 前言 在之前寫過一篇關於mysql分庫分表的文章,那篇文章只是給大家提供了一個思路,但是回覆下面有很多說是細節問題沒有提到。所以咔咔就在出了這篇文章。 本文只是針對其中的一個細節而已,比如如何落地MySQL的分庫分表,

MyBatis實現Mysql數據分庫操作和總結

用戶表 設計 行數 百萬 出現問題 網絡 自增 .html tro 閱讀目錄 前言 MyBatis實現分表最簡單步驟 分離的方式 分離的策略 分離的問題 分離的原則 實現分離的方式 總結 前言 作為一個數據庫,作為數據庫中的一張表,隨著用戶的增多隨著時間的推移,總有一

數據水平切分的實現原理解析——分庫,,主從,集群,負載均衡器(轉)

支付 讀取 dba 我們 課題研究 穩定性 存在 use 根據 第1章 引言 隨著互聯網應用的廣泛普及,海量數據的存儲和訪問成為了系統設計的瓶頸問題。對於一個大型的互聯網應用,每天幾十億的PV無疑對數據庫造成了相當高的負載。對於系統的穩定性和擴展性造成了極大的問題。通過數

記錄一次經歷的數據到分庫的過程

人力 per 靠譜 img center 沒有 tdd 推出 數據 前言 目前所在的的項目組,由於項目正在處於一個業務爆發期,每天數據的增長量已經給我們數據庫乃至系統造成了很多不確定的因數,前期依靠優化業務和SQL等方式暫時還能夠支撐住。但是最近發現某些表數據達到50

MySQL 高可用:mysql+mycat實現數據分片(分庫

native 分布 for 成功 img 問題 represent apache 新一代 本文引用於http://blog.csdn.net/kk185800961/article/details/51147029 MySQL 高可用:mysql+mycat實現數據庫分片(

布式數據中間件的實現原理介紹一:分庫【轉】

介紹 com CA 擴展 png HA 不同 訂單號 order 聲明:本文並非原創,轉自華為雲幫助中心的分布式數據庫中間件(DDM)服務的產品介紹。 分片是解決數據庫存儲容量限制的直接途徑。分片包括垂直分片與水平分片兩種方式。 垂直分片 垂直分片又叫縱向分割,

【原創】阿裏雲RDS數據超大實現

cpu bind 實現 表分區 HR 表數 alt bold inf [背景] 一張數據量約1億條數據的表,由於最初設計疏忽,未做分區,現需要根據創建時間字段來做分區; 業務要求,該表僅需要保留3個月的數據,數據量在9千萬~1億3千萬左右; 業務允許短時間停機,10分鐘左