当前位置: 代码迷 >> SQL >> mycat鐨勪娇鐢?sqlserver鍜宮ysql
  详细解决方案

mycat鐨勪娇鐢?sqlserver鍜宮ysql

热度:233   发布时间:2016-05-05 09:41:51.0
mycat鐨勪娇鐢?--sqlserver鍜宮ysql

鏁版嵁搴撲腑闂翠欢mycat鐨勪娇鐢?br>涓?銆佺幆澧?windows server 2008r2锛?鏍?16G鍐呭瓨锛?銆?sqlserver 銆?mysql 銆?mycat1.5.2
浜屻?佹祴璇曞墠绔?唬鐮侊紙鍙?彁渚汣#锛屼负浜嗚В鍐冲叕鍙稿師鏈夎?侀」鐩??java鐨勫埌mycat鐨刧ithub涓婇潰鑷??鏌ユ壘锛?br>聽聽 鏁版嵁搴撴搷浣滃?涓?br>using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
聽聽聽 public class MySQLHelper
聽聽聽 {
聽聽聽聽聽聽聽 private static string connectionString = "Server=10.10.3.234;Port=8066;Database=DataCenter_Odds;User=sa;Password=123456;";
聽聽聽聽聽聽聽 private static string SET_ENCODING="utf8";

聽聽聽聽聽聽聽 /// <summary>
聽聽聽聽聽聽聽 /// 鎵ц?鏌ヨ?璇?彞锛岃繑鍥濪ataSet
聽聽聽聽聽聽聽 /// </summary>
聽聽聽聽聽聽聽 /// <param name="SQLString">鏌ヨ?璇?彞</param>
聽聽聽聽聽聽聽 /// <returns>DataSet</returns>
聽聽聽聽聽聽聽 public static DataSet Query(string SQLString)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 using (MySqlConnection connection = new MySqlConnection(connectionString))
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 DataSet ds = new DataSet();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 try
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 try
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.Open();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 catch(Exception exp)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 finally
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 MySqlDataAdapter command = new MySqlDataAdapter(SQLString, connection);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 command.Fill(ds);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 catch (System.Data.SqlClient.SqlException ex)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 throw new Exception(ex.Message);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 finally
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.Close();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 return ds;
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 /// <summary>
聽聽聽聽聽聽聽 /// 鎵ц?SQL璇?彞锛岃繑鍥炲奖鍝嶇殑璁板綍鏁?br>聽聽聽聽聽聽聽 /// </summary>
聽聽聽聽聽聽聽 /// <param name="SQLString">SQL璇?彞</param>
聽聽聽聽聽聽聽 /// <returns>褰卞搷鐨勮?褰曟暟</returns>
聽聽聽聽聽聽聽 public static int ExecuteSql(string SQLString)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 using (MySqlConnection connection = new MySqlConnection(connectionString))
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 using (MySqlCommand cmd = new MySqlCommand(SQLString, connection))
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 try
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 int rows = 0;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 try
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.Open();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 catch (Exception exp)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 finally
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 rows = cmd.ExecuteNonQuery();聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 return rows;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 catch (System.Data.SqlClient.SqlException e)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.Close();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 throw e;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 finally
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 cmd.Dispose();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.Close();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 /// <summary>
聽聽聽聽聽聽聽 /// 鎵ц?SQL璇?彞锛岃繑鍥炲奖鍝嶇殑璁板綍鏁?br>聽聽聽聽聽聽聽 /// </summary>
聽聽聽聽聽聽聽 /// <param name="SQLString">SQL璇?彞</param>
聽聽聽聽聽聽聽 /// <returns>褰卞搷鐨勮?褰曟暟</returns>
聽聽聽聽聽聽聽 public static int ExecuteSql(string[] arrSql)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 using (MySqlConnection connection = new MySqlConnection(connectionString))
聽聽聽聽聽聽聽聽聽聽聽 {

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 try
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.Open();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 MySqlCommand cmdEncoding = new MySqlCommand(SET_ENCODING, connection);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 cmdEncoding.ExecuteNonQuery();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 int rows = 0;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 foreach (string strN in arrSql)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 using (MySqlCommand cmd = new MySqlCommand(strN, connection))
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 rows += cmd.ExecuteNonQuery();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 return rows;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 catch (System.Data.SqlClient.SqlException e)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.Close();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 throw e;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 finally
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.Close();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽 }

}
聽聽 娴嬭瘯浠g爜濡備笅
聽聽
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;
using System.IO;
using System.Data;

namespace ConsoleApplication1
{
聽聽聽 public class Program
聽聽聽 {聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 public static Guid executeFunctionMysql()
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 Guid str = new Guid();

聽聽聽聽聽聽聽聽聽聽聽 DataSet dataset = MySQLHelper.Query("select * from T_TEST1 where age > 15");
聽聽聽聽聽聽聽聽聽聽聽 //DataSet dataset = MySQLHelper.Query("select * from actor where first_name = 'PENELOPE' and聽 last_name='GUINESS' limit 1");

聽聽聽聽聽聽聽聽聽聽聽 DataTable dt = dataset.Tables[0];
聽聽聽聽聽聽聽聽聽聽聽 //閬嶅巻琛?br>聽聽聽聽聽聽聽聽聽聽聽 foreach (DataRow dr in dt.Rows)
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //閬嶅巻鍒?br>聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 for (int i = 0; i < dt.Columns.Count; i++)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Console.Write(dr[i].ToString() + " - " );
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Console.WriteLine();
聽聽聽聽聽聽聽聽聽聽聽 }

聽聽聽聽聽聽聽聽聽聽聽 return str;
聽聽聽聽聽聽聽 }

聽聽聽聽聽聽聽 public static int insertData()
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 DateTime start = DateTime.Now;
聽聽聽聽聽聽聽聽聽聽聽 Console.WriteLine(" 寮?濮嬫椂闂?" + start.ToString("yyyy-MM-dd HH:mm:ss,sss"));
聽聽聽聽聽聽聽聽聽聽聽 Random rand = new Random(10000);
聽聽聽聽聽聽聽聽聽聽聽 for (int i=1; i<10000; i++)
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 MySQLHelper.ExecuteSql("insert into T_TEST1(name,age) values('aaa_"+i+"',"+rand.Next(10000)+")");
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 DateTime end = DateTime.Now;
聽聽聽聽聽聽聽聽聽聽聽 Console.WriteLine(" 缁撴潫鏃堕棿 " + end.ToString("yyyy-MM-dd HH:mm:ss,sss"));
聽聽聽聽聽聽聽聽聽聽聽 Console.WriteLine("鍏辫姳璐癸細" + (end -start).TotalMilliseconds + " 姣??");
聽聽聽聽聽聽聽聽聽聽聽 return 0;
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 static void Main(string[] args)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log4net.config"));

聽聽聽聽聽聽聽聽聽聽聽 Console.Write(insertData());

聽聽聽聽聽聽聽聽聽聽聽 Console.Write(executeFunctionMysql());
聽聽聽聽聽聽聽聽聽聽聽 Console.Read();
聽聽聽聽聽聽聽 }
聽聽聽 }


}
聽聽 mycat1.5閰嶇疆濡備笅
聽聽 锛?锛夈?乻erver.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://org.opencloudb/">
<system>
<property name="defaultSqlParser">druidparser</property>
<property name="useCompression">1</property>
<property name="processorBufferChunk">40960</property>
<property name="processors">32</property>
<property name="processorExecutor">32</property>
<property name="maxStringLiteralLength">65535</property>
<property name="sequnceHandlerType">0</property>
<property name="backSocketNoDelay">1</property>
<property name="frontSocketNoDelay">1</property>
<property name="idleTimeout">300000</property>
<property name="frontWriteQueueSize">4096</property>
聽聽聽 <!--聽 <property name="useCompression">1</property>--> <!--1涓哄紑鍚痬ysql鍘嬬缉鍗忚?-->
<!-- <property name="processorBufferChunk">40960</property> -->
<!--
<property name="processors">1</property>
<property name="processorExecutor">32</property>
-->
<!--榛樿?鏄?5535 64K 鐢ㄤ簬sql瑙f瀽鏃舵渶澶ф枃鏈?暱搴?-->
<!--<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="mutiNodeLimitType">1</property> 0锛氬紑鍚?皬鏁伴噺绾э紙榛樿?锛?锛?锛氬紑鍚?嚎绾ф暟鎹?帓搴?br> 聽聽聽 <property name="mutiNodePatchSize">100</property> 浜跨骇鏁伴噺鎺掑簭鎵归噺
<property name="processors">32</property> <property name="processorExecutor">32</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> -->
</system>
<user name="sa">
<property name="password">jdd</property>
<property name="schemas">DataCenter_Odds</property>
</user>
<!-- <cluster> <node name="cobar1"> <property name="host">127.0.0.1</property>
<property name="weight">1</property> </node> </cluster> -->
<!-- <quarantine> <host name="1.2.3.4"> <property name="user">test</property>
</host> </quarantine> -->

</mycat:server>
聽 锛?锛夈?乻chema.xml閰嶇疆
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://org.opencloudb/">

<schema name="DataCenter_Odds" checkSQLschema="false" sqlMaxLimit="100">
<table name="T_TEST1_1" dataNode="dn1"/>
<table name="T_TEST1" dataNode="dn1,dn2" rule="mod-long"/>
</schema>

<dataNode name="dn1" dataHost="localhost1" database="DataCenter_Odds" />
<dataNode name="dn2" dataHost="localhost2" database="DataCenter_Odds" />

<dataHost name="localhost1" maxCon="1000" minCon="1" balance="1" writeType="0" dbType="sqlserver" dbDriver="jdbc">
<heartbeat></heartbeat>
<connectionInitSql></connectionInitSql>
<writeHost host="hostM1" url="jdbc:sqlserver://10.10.97.232:1433" user="sa" password="123456">
<readHost host="hostS1" url="jdbc:sqlserver://10.10.97.232:1433" user="sa" password="123456"></readHost>
</writeHost>
</dataHost>
<dataHost name="localhost2" maxCon="1000" minCon="1" balance="1" writeType="0" dbType="sqlserver" dbDriver="jdbc">
<heartbeat></heartbeat>
<connectionInitSql></connectionInitSql>
<writeHost host="hostM2"聽 url="jdbc:sqlserver://10.10.97.232:1433" user="sa" password="123456">
<readHost host="hostS2" url="jdbc:sqlserver://10.10.97.231:1433" user="sa" password="123456"></readHost>
</writeHost>
</dataHost>
</mycat:schema>
聽 (3)銆亀rapper閰嶇疆

#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=java
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=512M
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=-Xmx1G
wrapper.java.additional.11=-Xms1G

# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
wrapper.java.initmemory=512
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64
wrapper.java.maxmemory=512
# Application parameters.聽 Add parameters as needed starting from 1
wrapper.app.parameter.1=org.opencloudb.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
锛?锛夈?乺ule.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:rule SYSTEM "rule.dtd">
<mycat:rule xmlns:mycat="http://org.opencloudb/">
<tableRule name="rule1">
<rule>
<columns>id</columns>
<algorithm>func1</algorithm>
</rule>
</tableRule>

<tableRule name="rule2">
<rule>
<columns>user_id</columns>
<algorithm>func1</algorithm>
</rule>
</tableRule>

<tableRule name="sharding-by-intfile">
<rule>
<columns>sharding_id</columns>
<algorithm>hash-int</algorithm>
</rule>
</tableRule>
<tableRule name="auto-sharding-long">
<rule>
<columns>id</columns>
<algorithm>rang-long</algorithm>
</rule>
</tableRule>
<tableRule name="mod-long">
<rule>
<columns>age</columns>
<algorithm>mod-long</algorithm>
</rule>
</tableRule>
<tableRule name="sharding-by-murmur">
<rule>
<columns>id</columns>
<algorithm>murmur</algorithm>
</rule>
</tableRule>
<tableRule name="sharding-by-month">
<rule>
<columns>create_date</columns>
<algorithm>partbymonth</algorithm>
</rule>
</tableRule>
<tableRule name="latest-month-calldate">
<rule>
<columns>calldate</columns>
<algorithm>latestMonth</algorithm>
</rule>
</tableRule>

<tableRule name="auto-sharding-rang-mod">
<rule>
<columns>id</columns>
<algorithm>rang-mod</algorithm>
</rule>
</tableRule>

<tableRule name="jch">
<rule>
<columns>id</columns>
<algorithm>jump-consistent-hash</algorithm>
</rule>
</tableRule>

<function name="murmur"
class="org.opencloudb.route.function.PartitionByMurmurHash">
<property name="seed">0</property><!-- 榛樿?鏄? -->
<property name="count">2</property><!-- 瑕佸垎鐗囩殑鏁版嵁搴撹妭鐐规暟閲忥紝蹇呴』鎸囧畾锛屽惁鍒欐病娉曞垎鐗?-->
<property name="virtualBucketTimes">160</property><!-- 涓?涓?疄闄呯殑鏁版嵁搴撹妭鐐硅?鏄犲皠涓鸿繖涔堝?铏氭嫙鑺傜偣锛岄粯璁ゆ槸160鍊嶏紝涔熷氨鏄?櫄鎷熻妭鐐规暟鏄?墿鐞嗚妭鐐规暟鐨?60鍊?-->
<!-- <property name="weightMapFile">weightMapFile</property> 鑺傜偣鐨勬潈閲嶏紝娌℃湁鎸囧畾鏉冮噸鐨勮妭鐐归粯璁ゆ槸1銆備互properties鏂囦欢鐨勬牸寮忓~鍐欙紝浠ヤ粠0寮?濮嬪埌count-1鐨勬暣鏁板?间篃灏辨槸鑺傜偣绱㈠紩涓簁ey锛屼互鑺傜偣鏉冮噸鍊间负鍊笺?傛墍鏈夋潈閲嶅?煎繀椤绘槸姝f暣鏁帮紝鍚﹀垯浠?浠f浛 -->
<!-- <property name="bucketMapPath">/etc/mycat/bucketMapPath</property>
鐢ㄤ簬娴嬭瘯鏃惰?瀵熷悇鐗╃悊鑺傜偣涓庤櫄鎷熻妭鐐圭殑鍒嗗竷鎯呭喌锛屽?鏋滄寚瀹氫簡杩欎釜灞炴?э紝浼氭妸铏氭嫙鑺傜偣鐨刴urmur hash鍊间笌鐗╃悊鑺傜偣鐨勬槧灏勬寜琛岃緭鍑哄埌杩欎釜鏂囦欢锛屾病鏈夐粯璁ゅ?硷紝濡傛灉涓嶆寚瀹氾紝灏变笉浼氳緭鍑轰换浣曚笢瑗?-->
</function>
<function name="hash-int"
class="org.opencloudb.route.function.PartitionByFileMap">
<property name="mapFile">partition-hash-int.txt</property>
</function>
<function name="rang-long"
class="org.opencloudb.route.function.AutoPartitionByLong">
<property name="mapFile">autopartition-long.txt</property>
</function>
<function name="mod-long" class="org.opencloudb.route.function.PartitionByMod">
<!-- how many data nodes -->
<property name="count">2</property>
</function>

<function name="func1" class="org.opencloudb.route.function.PartitionByLong">
<property name="partitionCount">8</property>
<property name="partitionLength">128</property>
</function>
<function name="latestMonth"
class="org.opencloudb.route.function.LatestMonthPartion">
<property name="splitOneDay">24</property>
</function>
<function name="partbymonth"
class="org.opencloudb.route.function.PartitionByMonth">
<property name="dateFormat">yyyy-MM-dd</property>
<property name="sBeginDate">2015-01-01</property>
</function>

<function name="rang-mod" class="org.opencloudb.route.function.PartitionByRangeMod">
聽聽聽聽聽聽聽 <property name="mapFile">partition-range-mod.txt</property>
</function>

<function name="jump-consistent-hash" class="org.opencloudb.route.function.PartitionByJumpConsistentHash">
<property name="totalBuckets">3</property>
</function>
</mycat:rule>
閫氳繃浠ヤ笂鐨勬搷浣?鍗冲彲瀹屾垚mycat鐨勭浉鍏抽厤缃?br> 澶囨敞锛氬湪浣跨敤mycat鐨勬椂鍊?棣栧厛瑕佺煡閬?mycat鏄??mysql鐨勫皝瑁吢?鎵?浠ュ?闃熻?浠ヨ?闂甿ysql鐨勬柟寮忚繛鎺?br>聽聽聽聽聽聽聽聽聽 鍚屾椂闇?瑕佹敞鎰忎笉鍚岀殑sql涔嬮棿鐨勪笉鍏煎?闂??

  相关解决方案