數據分片概述
分庫/分表
- 什么是分庫分表?
- 將存放在一臺數據庫服務器中的數據,按照特定的方式進行拆分,分散存儲到多臺數據庫服務器中,以達到分散單臺服務器負載的效果
水平分割
- 橫向切分
- 按照表中指定字段的分片規則,將表記錄按行切分,分散存儲到多個數據庫中
垂直分割
- 縱向切分
- 將單個數據庫的多個表按照業務類型分類,分散存儲到不同的數據庫
MyCAT介紹
- 開源軟件,是基于Java的分布式數據庫系統中間件,為高并發環境的分布式存儲提供解決方案
- 適合數據大量寫入的存儲需求
- 支持MySQL、Oracle、Sqlserver、MongoDB等
- 提供數據讀寫分離服務
- 基于阿里巴巴Cobar進行研發的開源軟件
- mycat支持提供10種分片規則
- 枚舉法-----------sharding-by-intfile
- 固定分片--------rule 1
- 范圍約定--------auto-sharding-long
- 求模法------------mod-long
- 日期列分區法—sharding-by-date
- 通配取模----------sharding-by-pattern
- ASCII碼求模通配----sharding-by-prefixpattern
- 編程指定----------sharding-by-substring
- 字符串拆分hash解析------sharding-by-stringhash
- 一致性hash-------sharding-by-murmur
解析SQL命令涉及到的表然后看對表的配置,如果有分片規則,則獲取SQL命令里的分片字段的值,并匹配分片函數,獲得分片列表然后將SQL命令往對應的數據庫去執行最后收集和處理所有的分片結果數據,并返回到客戶端
部署MyCAT服務
環境部署
IP規劃
拓撲結構
服務部署
步驟:
1.安裝軟件JDK(系統自帶),安裝mycat服務軟件包軟件包在此提取碼:w4e7
2. 配置數據分片
3. 配置數據庫服務器
4. 啟動Mycat服務
1.在數據庫服務器53、54、55主機中分別創建用于分片式存儲的庫db1、db2、db3
[root@host53 ~
]
mysql
> create database db1
;
mysql
> show databases
;
+--------------------+
| Database
|
+--------------------+
| information_schema
|
| db1
|
| mysql
|
| performance_schema
|
| sys
|
+--------------------+
5 rows
in set (0.00 sec
)[root@host54 ~
]
mysql
> create database db2
;
mysql
> show databases
;
+--------------------+
| Database
|
+--------------------+
| information_schema
|
| db2
|
| mysql
|
| performance_schema
|
| sys
|
+--------------------+
5 rows
in set (0.00 sec
)[root@host55 ~
]
mysql
> create database db3
;
mysql
> show databases
;
+--------------------+
| Database
|
+--------------------+
| information_schema
|
| db3
|
| mysql
|
| performance_schema
|
| sys
|
+--------------------+
5 rows
in set (0.01 sec
)2.在host56主機安裝mycat軟件以及Java軟件
[root@host56 ~
]
[root@host56 ~
]
openjdk version
"1.8.0_161"
OpenJDK Runtime Environment
(build 1.8.0_161-b14
)
OpenJDK 64-Bit Server VM
(build 25.161-b14, mixed mode
)
[root@host56 ~
]
[root@host56 ~
]
mycat
Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
[root@host56 ~
]
bin catlet conf lib logs version.txt
[root@host56 ~
]
[root@host56 ~
]
bin etc games include lib lib64 libexec mycat sbin share src
[root@host56 ~
]
[root@host56 mycat
]
目錄結構
[root@host56 mycat
]
bin
catlet
conf
lib
logs
version.txt
wrapper.log
mycat.log
配置文件說明
server.xml
schema.xml
rule.xml
其他文件
3.配置Mycat服務創建客戶端連接件使用的用戶 密碼 邏輯庫 權限
[root@host56 mycat
]
<user name
="root"> //連接mycat服務時使用的用戶名
<property name
="password">123456
</property
> //用戶連接mycat用戶時使用的密碼
<property name
="schemas">TESTDB
</property
> //邏輯庫名
</user
>
<user name
="user"><property name
="password">user
</property
><property name
="schemas">TESTDB
</property
><property name
="readOnly">true
</property
> //只讀權限,連接mycat服務后只有讀記錄的權限,不寫這一行則是可讀可寫
</user
> 定義數據分片存儲的表
---------------------------------------------------
定義分片的表
<schema
>......</schema
>
<table
>......</table
>
name
dataNode
rule
type
=global 定義數據節點
<dataNode 選項
=值,
....../
>
name
datahost
database 定義數據庫服務器IP地址及端口
<datahost 選項
=值,
......>...
</datahost
>
name
host
url
user
password
---------------------------------------------------
[root@mycat56 mycat
]
77 /root/schema.xml
[root@host56 mycat
]
[root@host56 mycat
]為了看到更為清晰的配置文件,可以將注釋行刪掉,大批量的刪除后再進入到文件內逐行刪除注釋行
<!-- --
>,最后的配置文件大約為38行左右
[root@host56 mycat
]
[root@host56 mycat
]
[root@host56 mycat
]
38 /usr/local/mycat/conf/schema.xml
[root@host56 mycat
]1
<?xml version
="1.0"?
>2
<!DOCTYPE mycat:schema SYSTEM
"schema.dtd">3
<mycat:schema xmlns:mycat
="http://io.mycat/">4 5
<schema name
="TESTDB" checkSQLschema
="false" sqlMaxLimit
="100">6
<table name
="travelrecord" dataNode
="dn1,dn2,dn3" rule
="auto-sharding- long" /
>7 8
<table name
="company" primaryKey
="ID" type
="global" dataNode
="dn1,dn2, dn3" /
>9
<table name
="goods" primaryKey
="ID" type
="global" dataNode
="dn1,dn2,dn 3" /
>10
<table name
="hotnews" primaryKey
="ID" autoIncrement
="true" dataNode
="d n1,dn2,dn3"11 rule
="mod-long" /
>12
<table name
="employee" primaryKey
="ID" dataNode
="dn1,dn2,dn3"13 rule
="sharding-by-intfile" /
>14
<table name
="customer" primaryKey
="ID" dataNode
="dn1,dn2,dn3"15 rule
="sharding-by-intfile">16
<childTable name
="orders" primaryKey
="ID" joinKey
="customer_id "17 parentKey
="id">18
<childTable name
="order_items" joinKey
="order_id"19 parentKey
="id" /
>20
</childTable
>21
<childTable name
="customer_addr" primaryKey
="ID" joinKey
="cust omer_id"22 parentKey
="id" /
>23
</table
>24
</schema
>25
<dataNode name
="dn1" dataHost
="mysql53" database
="db1" /
>26
<dataNode name
="dn2" dataHost
="mysql54" database
="db2" /
>27
<dataNode name
="dn3" dataHost
="mysql55" database
="db3" /
>28 29
<dataHost name
="mysql53" maxCon
="1000" minCon
="10" balance
="0" 30 writeType
="0" dbType
="mysql" dbDriver
="native" switchType
="1 " slaveThreshold
="100">31
<heartbeat
>select user
()</heartbeat
>32
<writeHost host
="hostM1" url
="192.168.4.53:3306" user
="tian" 33 password
="123qqq...A"> 34
</writeHost
> 35
</dataHost
> 36 37
<dataHost name
="mysql54" maxCon
="1000" minCon
="10" balance
="0" 38 writeType
="0" dbType
="mysql" dbDriver
="native" switchType
="1 " slaveThreshold
="100"> 39
<heartbeat
>select user
()</heartbeat
> 40
<writeHost host
="hostM2" url
="192.168.4.54:3306" user
="tian"41 password
="123qqq...A">42
</writeHost
> 43
</dataHost
> 44 45
<dataHost name
="mysql55" maxCon
="1000" minCon
="10" balance
="0" 46 writeType
="0" dbType
="mysql" dbDriver
="native" switchType
="1 " slaveThreshold
="100">47
<heartbeat
>select user
()</heartbeat
>48
<writeHost host
="hostM3" url
="192.168.4.55:3306" user
="tian"49 password
="123qqq...A">50
</writeHost
>51
</dataHost
>52
</mycat:schema
>
4.配置數據庫服務器
首先確認53、54、55主機是否有相對應的庫,授權給配置文件中的用戶登錄
53主機:
mysql
> show databases
;
+--------------------+
| Database
|
+--------------------+
| information_schema
|
| db1
|
| mysql
|
| performance_schema
|
| sys
|
+--------------------+
5 rows
in set (0.00 sec
)mysql
> grant all on *.* to tian@
"%" identified by
"123qqq...A";
Query OK, 0 rows affected, 1 warning
(0.10 sec
)54主機:
mysql
> show databases
;
+--------------------+
| Database
|
+--------------------+
| information_schema
|
| db2
|
| mysql
|
| performance_schema
|
| sys
|
+--------------------+
5 rows
in set (0.00 sec
)mysql
> grant all on *.* to tian@
"%" identified by
"123qqq...A";
Query OK, 0 rows affected, 1 warning
(0.00 sec
)55主機:
mysql
> show databases
;
+--------------------+
| Database
|
+--------------------+
| information_schema
|
| db3
|
| mysql
|
| performance_schema
|
| sys
|
+--------------------+
5 rows
in set (0.01 sec
)mysql
> grant all on *.* to tian@
"%" identified by
"123qqq...A";
Query OK, 0 rows affected, 1 warning
(0.00 sec
)5.啟動Mycat服務測試數據庫的授權用戶(記得要關防火墻)
[root@host50 ~
]
[root@host50 ~
]
[root@host50 ~
]啟動服務
[root@host56 mycat
]
Starting Mycat-server
...
[root@host56 mycat
]
tcp6 0 0 :::8066 :::* LISTEN 1951/java
[root@host56 mycat
]PID TTY TIME CMD1951 ? 00:00:02 java
[root@host56 mycat
]
mycat.log mycat.pid wrapper.log查看報錯動態輸出:
[root@host56 mycat
]6.客戶端訪問分片服務器56
[root@host50 ~
]
MySQL
[(none
)]> show databases
;
+----------+
| DATABASE
|
+----------+
| TESTDB
|
+----------+
1 row
in set (0.00 sec
)
MySQL
[(none
)]> use TESTDB
;
MySQL
[TESTDB
]> show tables
;
+------------------+
| Tables
in TESTDB
|
+------------------+
| company
|
| customer
|
| customer_addr
|
| employee
|
| goods
|
| hotnews
|
| orders
|
| order_items
|
| travelrecord
|
+------------------+
9 rows
in set (0.00 sec
)MySQL
[TESTDB
]> desc company
;
ERROR 1146
(42S02
): Table
'db3.company' doesn
't exist
MySQL [TESTDB]> desc company;
ERROR 1146 (42S02): Table 'db2.company
' doesn't exist
MySQL
[TESTDB
]> desc company
;
ERROR 1146
(42S02
): Table
'db1.company' doesn't exist
====================================================================
如果啟動服務后查不到端口號,可以進行如下操作
[root@host56 ~
]
[root@host56 logs
]
2020-02 mycat.log mycat.pid wrapper.log
[root@host56 logs
]
[root@host56 logs
]
Starting Mycat-server
...
===================================================================
分片規則
- 枚舉法(sharding-by-intfile)
- 字段值必須在規則文件定義的值里選擇
1. 查看表使用的分片規則
[root@host56 mycat
]<table name
="employee" primaryKey
="ID" dataNode
="dn1,dn2,dn3"rule
="sharding-by-intfile" /
> <table name
="customer" primaryKey
="ID" dataNode
="dn1,dn2,dn3"rule
="sharding-by-intfile">
2. 查看分片規則使用的函數
[root@host56 mycat
]<tableRule name
="sharding-by-intfile"> <rule
><columns
>sharding_id
</columns
> <algorithm
>hash-int
</algorithm
> </rule
></tableRule
>
3. 查看函數確定分片字段名稱
<function name
="hash-int"class
="io.mycat.route.function.PartitionByFileMap"> <property name
="mapFile">partition-hash-int.txt
</property
> </function
>定義分片字段值列表
:[root@host56 conf
]
10000
=0
10010
=1
10020
=2
[root@host56 conf
]
Stopping Mycat-server
...
Stopped Mycat-server.
Starting Mycat-server
...
[root@host56 conf
]
tcp LISTEN 0 100 :::8066 :::* users:
(("java",pid
=2236,fd
=78
))4.建表(表的字段由第1 2 3步決定)
[root@host50 ~
]
MySQL
[(none
)]> use TESTDB
;
MySQL
[TESTDB
]> create table employee
( -
> ID int primary key auto_increment ,-
> sharding_id int ,-
> name char
(10
) ,-
> addree varchar
(50
) ,-
> mail varchar
(50
)-
> );
Query OK, 0 rows affected
(0.13 sec
)MySQL
[TESTDB
]> desc employee
;
+-------------+-------------+------+-----+---------+----------------+
| Field
| Type
| Null
| Key
| Default
| Extra
|
+-------------+-------------+------+-----+---------+----------------+
| ID
| int
(11
) | NO
| PRI
| NULL
| auto_increment
|
| sharding_id
| int
(11
) | YES
| | NULL
| |
| name
| char
(10
) | YES
| | NULL
| |
| addree
| varchar
(50
) | YES
| | NULL
| |
| mail
| varchar
(50
) | YES
| | NULL
| |
+-------------+-------------+------+-----+---------+----------------+
5 rows
in set (0.03 sec
)5.插入記錄插入數據:MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10030 ,
"bob",
"usa" ,
"bob@111.com");
ERROR 1064
(HY000
): can't
find any valid datanode :EMPLOYEE -
> SHARDING_ID -
> 10030
MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10000 ,
"bob",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.03 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10000 ,
"aaa",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10000 ,
"bbb",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10010 ,
"sss",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10010 ,
"ddd",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10010 ,
"fff",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10010 ,
"ggg",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10020 ,
"qqq",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.05 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10020 ,
"www",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10020 ,
"eee",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.00 sec
)MySQL
[TESTDB
]> insert into employee
(sharding_id ,name ,addree ,mail
) values
(10020 ,
"rrr",
"usa" ,
"bob@111.com");
Query OK, 1 row affected
(0.01 sec
)6.在數據庫服務器53/54/55主機查看數據是否成功分片存儲到各個主機
[root@host53 ~
]mysql
> select * from db1.employee
;
+----+-------------+------+--------+-------------+
| ID
| sharding_id
| name
| addree
| mail
|
+----+-------------+------+--------+-------------+
| 1
| 10000
| bob
| usa
| bob@111.com
|
| 2
| 10000
| aaa
| usa
| bob@111.com
|
| 3
| 10000
| bbb
| usa
| bob@111.com
|
+----+-------------+------+--------+-------------+
3 rows
in set (0.00 sec
)mysql
> select * from db2.employee
;
+----+-------------+------+--------+-------------+
| ID
| sharding_id
| name
| addree
| mail
|
+----+-------------+------+--------+-------------+
| 1
| 10010
| sss
| usa
| bob@111.com
|
| 2
| 10010
| ddd
| usa
| bob@111.com
|
| 3
| 10010
| fff
| usa
| bob@111.com
|
| 4
| 10010
| ggg
| usa
| bob@111.com
|
+----+-------------+------+--------+-------------+
4 rows
in set (0.00 sec
)[root@host55 ~
]
mysql
> select * from db3.employee
;
+----+-------------+------+--------+-------------+
| ID
| sharding_id
| name
| addree
| mail
|
+----+-------------+------+--------+-------------+
| 1
| 10020
| qqq
| usa
| bob@111.com
|
| 2
| 10020
| www
| usa
| bob@111.com
|
| 3
| 10020
| eee
| usa
| bob@111.com
|
| 4
| 10020
| rrr
| usa
| bob@111.com
|
+----+-------------+------+--------+-------------+
4 rows
in set (0.00 sec
)MySQL
[TESTDB
]> select * from employee
;
+----+-------------+------+--------+-------------+
| ID
| sharding_id
| name
| addree
| mail
|
+----+-------------+------+--------+-------------+
| 1
| 10000
| bob
| usa
| bob@111.com
|
| 2
| 10000
| aaa
| usa
| bob@111.com
|
| 3
| 10000
| bbb
| usa
| bob@111.com
|
| 1
| 10020
| qqq
| usa
| bob@111.com
|
| 2
| 10020
| www
| usa
| bob@111.com
|
| 3
| 10020
| eee
| usa
| bob@111.com
|
| 4
| 10020
| rrr
| usa
| bob@111.com
|
| 1
| 10010
| sss
| usa
| bob@111.com
|
| 2
| 10010
| ddd
| usa
| bob@111.com
|
| 3
| 10010
| fff
| usa
| bob@111.com
|
| 4
| 10010
| ggg
| usa
| bob@111.com
|
+----+-------------+------+--------+-------------+
11 rows
in set (0.11 sec
)
1.查看配置文件使用求模法規則的表名
[root@host56 logs
]<table name
="hotnews" primaryKey
="ID" autoIncrement
="true" dataNode
="dn1,dn2,dn3"rule
="mod-long" /
>2.查看表的分片字段名及使用的函數配置
[root@host56 logs
]
<tableRule name
="mod-long"><rule
><columns
>x
</columns
> <algorithm
>mod-long
</algorithm
> </rule
></tableRule
><function name
="mod-long" class
="io.mycat.route.function.PartitionByMod"><!-- how many data nodes --
><property name
="count">3
</property
> </function
>3.重啟mycat服務
[root@host56 logs
]
Stopping Mycat-server
...
Mycat-server was not running.
[root@host56 logs
]
Starting Mycat-server
...
[root@host56 logs
]
Mycat-server is running
(1846
).4.客戶端連接mycat服務建表存儲數據
[root@host50 ~
]
MySQL
[(none
)]> show databases
;
+----------+
| DATABASE
|
+----------+
| TESTDB
|
+----------+
1 row
in set (0.01 sec
)
MySQL
[(none
)]> use TESTDB
;MySQL
[TESTDB
]> show tables
;
+------------------+
| Tables
in TESTDB
|
+------------------+
| company
|
| customer
|
| customer_addr
|
| employee
|
| goods
|
| hotnews
|
| orders
|
| order_items
|
| travelrecord
|
+------------------+
9 rows
in set (0.00 sec
)MySQL
[(none
)]> create table TESTDB.hotnews
;
ERROR 3000
(HY000
): No MyCAT Database selectedMySQL
[(none
)]> use TESTDB
;
MySQL
[TESTDB
]> create table hotnews
(ID int primary key auto_increment , x int , title char
(25
) , comment varchar
(150
) );
Query OK, 0 rows affected
(10.10 sec
)MySQL
[TESTDB
]> insert into hotnews
(x , title , comment
) values
( 10,
"dddd" ,
"yyyy");
ERROR 1264
(22003
): Out of range value
for column
'ID' at row 1MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 11,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.07 sec
)MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 11,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 10,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.02 sec
)MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 10,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.01 sec
)
MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 9,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.04 sec
)MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 9,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 11,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.01 sec
)MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 10,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.00 sec
)MySQL
[TESTDB
]> insert into hotnews
(ID ,x , title , comment
) values
(null , 9,
"dddd" ,
"yyyy");
Query OK, 1 row affected
(0.00 sec
)5.在3臺數據庫服務器本機查看數據
[root@host53 ~
]
mysql
> select * from db1.hotnews
;
+----+------+-------+---------+
| ID
| x
| title
| comment
|
+----+------+-------+---------+
| 1
| 9
| dddd
| yyyy
|
| 2
| 9
| dddd
| yyyy
|
| 3
| 9
| dddd
| yyyy
|
+----+------+-------+---------+
3 rows
in set (0.00 sec
)[root@host54 ~
]
mysql
> select * from db2.hotnews
;
+----+------+-------+---------+
| ID
| x
| title
| comment
|
+----+------+-------+---------+
| 1
| 10
| dddd
| yyyy
|
| 2
| 10
| dddd
| yyyy
|
| 3
| 10
| dddd
| yyyy
|
+----+------+-------+---------+
3 rows
in set (0.00 sec
)[root@host55 ~
]
mysql
> select * from db3.hotnews
;
+----+------+-------+---------+
| ID
| x
| title
| comment
|
+----+------+-------+---------+
| 1
| 11
| dddd
| yyyy
|
| 2
| 11
| dddd
| yyyy
|
| 3
| 11
| dddd
| yyyy
|
+----+------+-------+---------+
3 rows
in set (0.00 sec
)[root@host50 ~
]
MySQL
[TESTDB
]> select * from hotnews
;
+----+------+-------+---------+
| ID
| x
| title
| comment
|
+----+------+-------+---------+
| 1
| 9
| dddd
| yyyy
|
| 2
| 9
| dddd
| yyyy
|
| 3
| 9
| dddd
| yyyy
|
| 1
| 10
| dddd
| yyyy
|
| 2
| 10
| dddd
| yyyy
|
| 3
| 10
| dddd
| yyyy
|
| 1
| 11
| dddd
| yyyy
|
| 2
| 11
| dddd
| yyyy
|
| 3
| 11
| dddd
| yyyy
|
+----+------+-------+---------+
9 rows
in set (0.07 sec
)
添加新庫/新表
1.添加新庫
[root@host56 logs
]82
<property name
="schemas">TESTDB,GAME
</property
>97
<property name
="schemas">TESTDB,GAME
</property
>2.添加新表
[root@host56 ~
]5
<schema name
="GAME" checkSQLschema
="false" sqlMaxLimit
="100">6
<table name
="teacher" dataNode
="dn1,dn2,dn3" rule
="mod-long" /
> 7
<table name
="class" dataNode
="dn1,dn2,dn3" type
="global" /
> 8
</schema
>3.重啟mycat服務
[root@host56 logs
]
Stopping Mycat-server
...
Mycat-server was not running.
[root@host56 logs
]
Starting Mycat-server
...
[root@host56 logs
]
tcp LISTEN 0 100 :::8066 :::* users:
(("java",pid
=2762,fd
=77
))
[root@host50 ~
]2.創建新表存數據
MySQL
[(none
)]> show databases
;
+----------+
| DATABASE
|
+----------+
| GAME
|
| TESTDB
|
+----------+
2 rows
in set (0.01 sec
)MySQL
[(none
)]> use GAME
;MySQL
[GAME
]> create table class
(name char
(10
) ,age int
);
Query OK, 0 rows affected
(0.04 sec
)MySQL
[GAME
]> insert into class values
("yyy" ,19
);
Query OK, 1 row affected
(0.07 sec
)MySQL
[GAME
]> insert into class values
("yyy" ,19
);
Query OK, 1 row affected
(0.03 sec
)MySQL
[GAME
]> insert into class values
("yyy" ,19
);
Query OK, 1 row affected
(0.01 sec
)MySQL
[GAME
]> insert into class values
("yyy" ,19
);
Query OK, 1 row affected
(0.01 sec
)MySQL
[GAME
]> insert into class values
("zzz" ,20
);
Query OK, 1 row affected
(0.01 sec
)MySQL
[GAME
]> insert into class values
("zzz" ,20
);
Query OK, 1 row affected
(0.00 sec
)MySQL
[GAME
]> insert into class values
("zzz" ,20
);
Query OK, 1 row affected
(0.02 sec
)MySQL
[GAME
]> select * from class
;
+------+------+
| name
| age
|
+------+------+
| yyy
| 19
|
| yyy
| 19
|
| yyy
| 19
|
| yyy
| 19
|
| zzz
| 20
|
| zzz
| 20
|
| zzz
| 20
|
+------+------+
7 rows
in set (0.05 sec
)3.在數據庫服務器查看
[root@host53 ~
]
mysql
> select * from db1.class
;
+------+------+
| name
| age
|
+------+------+
| yyy
| 19
|
| yyy
| 19
|
| yyy
| 19
|
| yyy
| 19
|
| zzz
| 20
|
| zzz
| 20
|
| zzz
| 20
|
+------+------+
7 rows
in set (0.00 sec
)[root@host54 ~
]mysql
> select * from db2.class
;
+------+------+
| name
| age
|
+------+------+
| yyy
| 19
|
| yyy
| 19
|
| yyy
| 19
|
| yyy
| 19
|
| zzz
| 20
|
| zzz
| 20
|
| zzz
| 20
|
+------+------+
7 rows
in set (0.01 sec
)[root@host55 ~
]
mysql
> select * from db3.class
;
+------+------+
| name
| age
|
+------+------+
| yyy
| 19
|
| yyy
| 19
|
| yyy
| 19
|
| yyy
| 19
|
| zzz
| 20
|
| zzz
| 20
|
| zzz
| 20
|
+------+------+
7 rows
in set (0.00 sec
)
總結
mycat介紹:做數據分片存儲的軟件10種分片規則:枚舉法,求模法配置文件:配置連接用戶,邏輯庫名,邏輯表,分片字段名服務管理:啟動,停止,查看狀態,kill killall分片規則的使用:水平分割 mod-long sharding-by-intfile添加新庫新表客戶端連接
總結
以上是生活随笔為你收集整理的DBA(五):数据分片、Mycat服务的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。