docs: add 'SQL Operations' section (#190)

Signed-off-by: zyy17 <zyylsxm@gmail.com>

Signed-off-by: zyy17 <zyylsxm@gmail.com>
This commit is contained in:
Yong
2022-08-19 17:26:07 +08:00
committed by GitHub
parent 9a68e4ca88
commit cab20cfd3e

View File

@@ -39,6 +39,8 @@ brew install openssl
## Usage
### Start Datanode
```
// Start datanode with default options.
cargo run -- datanode start
@@ -59,3 +61,47 @@ Start datanode with config file:
```
cargo run -- --log-dir=logs --log-level=debug datanode start -c ./config/datanode.example.toml
```
### SQL Operations
1. Connecting DB by [mysql client](https://dev.mysql.com/downloads/mysql/):
```
# The datanode listen on port 3306 by default.
mysql -h 127.0.0.1 -P 3306
```
2. Create table:
```SQL
CREATE TABLE monitor (
host STRING,
ts BIGINT,
cpu DOUBLE DEFAULT 0,
memory DOUBLE,
TIME INDEX (ts),
PRIMARY KEY(ts,host)) ENGINE=mito WITH(regions=1);
```
3. Insert data:
```SQL
INSERT INTO monitor(host, cpu, memory, ts) VALUES ('host1', 66.6, 1024, 1660897955);
INSERT INTO monitor(host, cpu, memory, ts) VALUES ('host2', 77.7, 2048, 1660897956);
INSERT INTO monitor(host, cpu, memory, ts) VALUES ('host3', 88.8, 4096, 1660897957);
```
4. Query data:
```SQL
mysql> SELECT * FROM monitor;
+-------+------------+------+--------+
| host | ts | cpu | memory |
+-------+------------+------+--------+
| host1 | 1660897955 | 66.6 | 1024 |
| host2 | 1660897956 | 77.7 | 2048 |
| host3 | 1660897957 | 88.8 | 4096 |
+-------+------------+------+--------+
3 rows in set (0.01 sec)
```
You can delete your data by removing `/tmp/greptimedb`.