Doris 采用 MySQL 协议进行通信,用户可通过 MySQL client 或者 MySQL JDBC连接到 Doris 集群。
选择 MySQL client 版本时建议采用5.1 之后的版本,因为 5.1 之前不能支持长度超过 16 个字符的用户名。
#修改root密码
mysql> SET PASSWORD FOR 'root' = PASSWORD('12345678');#创建新用户
mysql> CREATE USER 'doris_test' IDENTIFIED BY '123456';#创建数据库
CREATE DATABASE example_db;#查看数据库
SHOW DATABASES;#账户授权
mysql> GRANT ALL ON example_db TO doris_test;#用新账号登录
mysql -h FE_HOST -P9030 -udoris_test -p123456#切换数据库
USE example_db;#创建表(单分区)
CREATE TABLE table1
(siteid INT DEFAULT '10',citycode SMALLINT,username VARCHAR(32) DEFAULT '',pv BIGINT SUM DEFAULT '0'
)
AGGREGATE KEY(siteid, citycode, username)
DISTRIBUTED BY HASH(siteid) BUCKETS 10
PROPERTIES("replication_num" = "1");#创建表(多分区)
CREATE TABLE table2
(event_day DATE,siteid INT DEFAULT '10',citycode SMALLINT,username VARCHAR(32) DEFAULT '',pv BIGINT SUM DEFAULT '0'
)
AGGREGATE KEY(event_day, siteid, citycode, username)
PARTITION BY RANGE(event_day)
(PARTITION p201706 VALUES LESS THAN ('2017-07-01'),PARTITION p201707 VALUES LESS THAN ('2017-08-01'),PARTITION p201708 VALUES LESS THAN ('2017-09-01')
)
DISTRIBUTED BY HASH(siteid) BUCKETS 10
PROPERTIES("replication_num" = "1");#查看表
SHOW TABLES;
DESC table1;
DESC table2;#插入数据
insert into example_db.table1 values
(1,1,'jim',2),
(2,1,'grace',2),
(3,2,'tom',2),
(4,3,'bush',3),
(5,3,'helen',3);insert into example_db.table2 values
('2017-07-03',1,1,'jim',2),
('2017-07-05',2,1,'grace',2),
('2017-07-12',3,2,'tom',2),
('2017-07-15',4,3,'bush',3),
('2017-07-12',5,3,'helen',3);#查询数据
mysql> SELECT * FROM table1 LIMIT 3;
mysql> SELECT * FROM table1 ORDER BY citycode;#Join 查询
mysql> SELECT SUM(table1.pv) FROM table1 JOIN table2 WHERE table1.siteid = table2.siteid;#子查询
mysql> SELECT SUM(pv) FROM table2 WHERE siteid IN (SELECT siteid FROM table1 WHERE siteid > 2);#Rollup
ALTER TABLE table1 ADD ROLLUP rollup_city(citycode, pv);
desc table1 all;#查询/修改内存限制
SHOW VARIABLES LIKE "%mem_limit%";
SET exec_mem_limit = 8589934592;#查询超时
SHOW VARIABLES LIKE "%query_timeout%";
SET query_timeout = 60; # 60秒
更多信息可参见官方文档地址:https://doris.apache.org/zh-CN/docs/data-table/basic-usage
往期精彩内容推荐
一文看懂Doris数据模型(含样例,建议收藏)
【快捷部署】001_Doris(2.0.3)
易经智慧解码数字化转型:象数理视角下的未来探索
数字化转型对企业有什么意义
数字化时代的利器:数仓助力企业破局突围