集群
创建一个集群
请参考 Kubernetes 以获得关于创建 Kubernetes 集群的信息。
分布式读/写
SQL
可以按照步骤使用 SQL 来进行分布式插入和查询:
-
使用 MySQL cli 连接到 Frontend。
mysql -h 127.0.0.1 -P 4002
-
通过
CREATE
语句创建一个分布式表。CREATE TABLE dist_table(
ts TIMESTAMP DEFAULT current_timestamp(),
n INT,
row_id INT,
PRIMARY KEY(n),
TIME INDEX (ts)
)
PARTITION BY RANGE COLUMNS (n) (
PARTITION r0 VALUES LESS THAN (5),
PARTITION r1 VALUES LESS THAN (9),
PARTITION r2 VALUES LESS THAN (MAXVALUE),
)
engine=mito;结果如下:
mysql> CREATE TABLE dist_table(
-> ts TIMESTAMP DEFAULT current_timestamp(),
-> n INT,
-> row_id INT,
-> TIME INDEX (ts)
-> TIME INDEX (ts)
-> )
-> PARTITION BY RANGE COLUMNS (n) (
-> PARTITION r0 VALUES LESS THAN (5),
-> PARTITION r1 VALUES LESS THAN (9),
-> PARTITION r2 VALUES LESS THAN (MAXVALUE),
-> )
-> engine=mito;
Query OK, 3 rows affected (0.09 sec)dist_table
被分布在Datanode
中。你可以参考 "Table Sharding" 了解更多细节。 -
通过
INSERT
语句输入一些数据。INSERT INTO dist_table(n, row_id) VALUES (1, 1);
INSERT INTO dist_table(n, row_id) VALUES (2, 2);
INSERT INTO dist_table(n, row_id) VALUES (3, 3);
INSERT INTO dist_table(n, row_id) VALUES (4, 4);
INSERT INTO dist_table(n, row_id) VALUES (5, 5);
INSERT INTO dist_table(n, row_id) VALUES (6, 6);
INSERT INTO dist_table(n, row_id) VALUES (7, 7);
INSERT INTO dist_table(n, row_id) VALUES (8, 8);
INSERT INTO dist_table(n, row_id) VALUES (9, 9);
INSERT INTO dist_table(n, row_id) VALUES (10, 10);
INSERT INTO dist_table(n, row_id) VALUES (11, 11);
INSERT INTO dist_table(n, row_id) VALUES (12, 12); -
通过
SELECT
语句执行查询:SELECT * FROM dist_table ORDER BY n LIMIT 5;
+---------------------+------+--------+
| ts | n | row_id |
+---------------------+------+--------+
| 2022-11-14 12:02:32 | 1 | 1 |
| 2022-11-14 12:02:32 | 2 | 2 |
| 2022-11-14 12:02:32 | 3 | 3 |
| 2022-11-14 12:02:32 | 4 | 4 |
| 2022-11-14 12:02:32 | 5 | 5 |
+---------------------+------+--------+
5 rows in set (0.081 sec)SELECT MAX(n) FROM dist_table;