当前位置:网站首页>[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;
边栏推荐
猜你喜欢

【深入理解TcaplusDB技术】查看TcaplusDB线上运行情况

使用 qrcodejs2 生成二维码详细API和参数

Traversal of trees and forests

【深入理解TcaplusDB技术】入门MySQL Driver

1.2----- mechanical design tools (CAD software) and hardware design tools (EDA software) and comparison

【深入理解TcaplusDB技术】入门Tcaplus SQL Driver

关键路径

0.1----- process of drawing PCB with AD

Matplotlib set axis scale interval

Nlp-d57-nlp competition D26 & skimming questions D13 & reading papers & finding bugs for more than an hour
随机推荐
C WinForm embedded flash
Definitions and terms of drawings
漫话Redis源码之一百一十九
A text to show you the memory leak
带超时的recv函数
第六章 操作位和位串(二)
Calendar control programming
Heap sort (principle plus code)
MySQL数据库DML操作练习
#夏日挑战赛# 【FFH】从零开始的鸿蒙机器学习之旅-NLP情感分析
一文带你读懂内存泄露
undefined reference 之坑
【深入理解TcaplusDB技术】TcaplusDB机型
socket的connect函数用法
【深入理解TcaplusDB知识库】部署TcaplusDB Local版常见问题
[deeply understand tcapulusdb technology] tcapulusdb transaction management - error troubleshooting
二叉排序树的查找、插入和删除
【深入理解TcaplusDB技术】TcaplusDB机型管理
How to use yincan IS903 to master DIY's own USB flash disk? (good items for practicing BGA welding)
【深入理解TcaplusDB技术】TcaplusDB机器如何初始化和上架