当前位置:网站首页>[in depth understanding of tcapulusdb technology] getting started with MySQL driver
[in depth understanding of tcapulusdb technology] getting started with MySQL driver
2022-06-22 20:02:00 【InfoQ】
【 In depth understanding of TcaplusDB technology 】 introduction MySQL Driver
- Single table is supported SELECT、INSERT、DELETE、UPDATE sentence ;
- SELECT、DELETE、UPDTATE Operation of the WHERE Clause must explicitly specify one or more primary keys , See the later 《SQL Grammar use reference 》;
- When the global index is configured , Support basic aggregation functions , See the later 《 Global index query 》;
- Temporary does not support prepared statement;
- Temporary does not support DDL, namely CREATE / DROP TABLE etc. ;
- I won't support it ORDER BY、GROUP BY;
- Cross table is not supported JOIN.
1. The version of the client or driver is compatible
- MySQL client Tools ,5.5.24
- Python OfMySQLdb, The actual bottom layer uses mysql c api Of 5.5.24 edition
- JDBC,mysql-connector-java-5.1.49
- .NET mysql driver 8.0.25
2. Table definition and table creation
2.1 The table definition
<?xml version="1.0" encoding="GBK" standalone="yes" ?>
<metalib name="demo_table" tagsetversion="1" version="1">
<struct name="user" version="1" primarykey="user_id,server_id" splittablekey="user_id">
<entry name="user_id" type="string" size="450" desc=" user ID"/>
<entry name="server_id" type="int64" desc=" The server ID" />
<entry name="nick_name" type="string" size="50" desc=" nickname "/>
<entry name="desc" type="string" size="1024" desc=" Description information "/>
<entry name="state" type="Tinyuint" defaultvalue="0" desc=" User state 0 : AVALIABLE, 1 DELETED"/>
<index name="index1" column="user_id"/>
<index name="index2" column="user_id,server_id"/>
</struct>
</metalib>
- Elements metalib yes xml The root element of the file .
- contain primarykey Of struct Element is a table , It doesn't contain primarykey Of struct The element is an ordinary structure .
- Every time the table structure is modified , The version attribute value needs to be added accordingly 1, The initial version is always 1.
- primarykey Property specifies the primary key field ; about generic surface , You can specify at most 8 Primary key fields , about list surface , You can specify 7 individual .
- splittablekey Property is equivalent to a partition key (shard key),TcaplusDB Tables are split and stored to multiple storage nodes .splittablekey Must be one of the primary key fields , A good splittablekey It should be highly decentralized , This means a wide range of values , String type is recommended .
- desc Property contains the description of the current element .
- entry Element defines a field , Supported value types include int32,string,char,int64,double,short etc. .
- index Element defines an index , The index must contain splittablekey. Because you can use the primary key to query the table , Therefore, the index should not be the same as the primary key attribute .
2.2 Table building process
# step0, Use the above xml Table definition of format , Save as .xml Suffix text , Such as table-define.xml.
# step1, Get into OMS page , Open... In the menu bar : The business management =〉 Watch management .
# step2, page Tab Column , Choose : Table to add
# step3, Select the business and cluster and check the game area , colony :test_set(1), Business :tdr_app(2), Game Zone ID: 3, Click again : Batch add table
# step4, In the page that comes out , Browse to the bottom of the page , Click on : Add... From local file , Select the sample table definition file downloaded from the above resources in the pop-up page :table-define.xml
# step5, Click on : Submit , Create a sample table : demo_table
# step6, Check whether the table is created ok, Get into : The business management => Watch management , Select the corresponding business (tdr_app) And the game area (3), See if demo_table Table information
3. Quick experience
3.1 Connection instructions
- MySQL Of
databaseThe concept of corresponding TcaplusDB In aBusinessOne of theDistrict, Use'appid.zoneid'As the database name , For example, the area where the example table is located is2.3.
- MySQL The address of the client or driver connection is Tcaplus Proxy Node IP + port , Can be found in OMS Of
Operational platform => State of the clusterPage view IP And port number .
- MySQL Before the first connection , You need to create a corresponding MySQL Users and give corresponding permissions , See the following graphic guidelines for the creation process .
'appid.zoneid'mysql_native_password3.2 Experience examples ( Use mysql client)
mysql -u user_name -p user_passwd --port=15755 --host=xxx.xxx.xxx.xxx 2.3
3.3 Experience examples ( Use .NET mysql driver)
public class Database
{
static MySqlConnection conn; // MySql Connect
const String server = "xxx.xxx.xxx.xxx"; // Server address , The client to connect to proxy Node IP
const String port = "15755"; // Port number , The client to connect to proxy Node Port
const String uid = "user_name"; // user name
const String pw = "user_passwd"; // password
const String db = "2.3"; // Library name , from TcaplusDB Business in ID And zoning ID Splicing into
public static Boolean Init()
{
try
{
if (conn == null)
{
conn = new MySqlConnection("server=" + server + ";port=" + port + ";user id=" + uid + ";password=" + pw + ";database=" + db);
conn.Open();
Console.WriteLine("database connected.");
}
return true;
}
catch (Exception e)
{
Console.WriteLine("Exception caught: {0}", e);
return false;
}
}
}
4. Data type support
5. SQL Grammar use reference
5.1 The insert
INSERT INTO demo (key1,key2,key3,value1,value2) values (x1,x2,x3,x4,x5);
INSERT INTO demo (key1,key2,key3,value1,value2) values (x1,x2,x3,x4,x5); INSERT INTO demo (key1,key2,key3,value1,value2) values (x6,x7,x8,x9,x10);
5.2 where Clause syntax restrictions
WHERE key1=x1 AND key2=x2 AND key3=x3;
WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
WHERE key1=x1 AND key2=x2;
WHERE key1=x1 AND key2=x2 AND ( Filter conditions );
5.3 Delete operation
DELETE FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3;
DELETE FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
DELETE FROM demo WHERE (key1=x1 AND key2=x2 AND key3=x3) OR (key1=x4 AND key2=x5 AND key3=x6);
5.4 update operation
UPDATE demo SET value1=x1, value2=x2 WHERE key1=x1 AND key2=x2 AND key3=x3;
UPDATE demo SET value1=x1, value2=x2 WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
UPDATE demo SET value1=x1, value2=x2 WHERE (key1=x3 AND key2=x4 AND key3=x5) OR (key1=x6 AND key2=x7 AND key3=x8);
5.5 Query operation
SELECT * FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3;
SELECT * FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
SELECT key1,value1 FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3;
SELECT key1,value1 FROM demo WHERE key1=x1 AND key2=x2 AND key3=x3 AND ( Filter conditions );
SELECT * FROM demo WHERE key1=x1 AND key2=x2;
SELECT * FROM demo WHERE key1=x1 AND key2=x2 AND ( Filter conditions );
SELECT key1,value1 FROM demo WHERE key1=x1 AND key2=x2;
SELECT key1,value1 FROM demo WHERE key1=x1 AND key2=x2 AND ( Filter conditions );
SELECT * FROM demo WHERE (key1=x1 AND key2=x2 AND key3=x3) OR (key1=x4 AND key2=x5 AND key3=x6);
SELECT * FROM demo WHERE (key1=x1 AND key2=x2) OR (key1=x3 AND key2=x4);
6. Global index query
6.1 Supported by sql Query statement
Conditions of the query
SELECT * FROM `mail` WHERE user_id>="10004" AND server_id=100;
SELECT * FROM `mail` WHERE user_id BETWEEN 10000 AND 10003 AND server_id=100;
SELECT * FROM `mail` WHERE user_id="10000" AND server_id=100 AND mail_id LIKE "210507%";
SELECT * FROM `mail` WHERE user_id>="10004" OR server_id<=200;
Paging query
SELECT * FROM mail WHERE user_id>"10000" LIMIT 100 OFFSET 2;
Aggregate query
SELECT server_id, COUNT(DISTINCT user_id), COUNT(*), SUM(state) FROM \`mail\` WHERE user_id>="10000" AND server_id=100;
select count(distinct(a)) from table where a > 1000;
边栏推荐
猜你喜欢

Damp 3D printer consumables

记可视化项目代码设计的心路历程以及理解

二叉排序树的查找、插入和删除

元宇宙怎么就这么火,市场喊起来的10万亿是吹嘘还是真相?

matplotlib设置坐标轴刻度间隔

0816 shortcomings of Feida (improvement direction)

Traversal of trees and forests

Comparison of NAND flash particles SLC, MLC, TLC and QLC

Matplotlib set axis scale interval

使用 qrcodejs2 生成二维码详细API和参数
随机推荐
【深入理解TcaplusDB技术】TcaplusDB常规单据
【深入理解TcaplusDB技术】TcaplusDB 表管理——修改表
[compréhension approfondie de la technologie tcaplusdb] exploitation et entretien de tcaplusdb - inspection quotidienne des patrouilles
Antd tree tree tree selector subclass required
【小资说库】掰扯下概念:数据、数据库、数据库系统、数据库管理系统、数据库技术
【深入理解TcaplusDB技术】TcaplusDB机器如何初始化和上架
iVX无代码挑战五秒游戏制作
[petty bourgeoisie database] break down the concept: data, database, database system, database management system, database technology
Modify the antd tree component so that its subclasses are arranged horizontally.
优化了一半的SQL
漫话Redis源码之一百二十二
51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
再谈SQL profile : 到底能不能固定执行计划?
The array objects are filled in one by one according to the ID (fill Arr1 into arr2)
【深入理解TcaplusDB技术】TcaplusDB 表管理——清理表
[in depth understanding of tcapulusdb technology] new models of tcapulusdb
Hash table (hash table)
堆排序(原理加代码)
libcef最新下载地址-在VS2015下编译为MD-动态链接
归并排序(递归和迭代实现)