一、创建库
>create database test
>create database test
二、表
2.1创建measurement
如果userInfo这个measurement不存在,则新建一个
> insert userInfo,name=blog userId=10,blog="ksksks"
> show measurements;
name: measurements
name
----
userInfo
> select * from userInfo
name: userInfo
time blog name userId
---- ---- ---- ------
1568467969678950115 ksksks blog 10
如果userInfo这个measurement不存在,则新建一个
> insert userInfo,name=blog userId=10,blog="ksksks"
> show measurements;
name: measurements
name
----
userInfo
> select * from userInfo
name: userInfo
time blog name userId
---- ---- ---- ------
1568467969678950115 ksksks blog 10
2.2普通查询表
> use test
Using database test
#查看有多少表
> show measurements
#或者直接指定数据库
> show measurements on test
name: measurements
name
----
userInfo
> use test
Using database test
#查看有多少表
> show measurements
#或者直接指定数据库
> show measurements on test
name: measurements
name
----
userInfo
2.3过滤查询
也可以在不执行use databaseName的时候,进行查看;
- 而且还支持按名进行匹配,语法为
SHOW MEASUREMENTS [ON <database_name>] [WITH MEASUREMENT <regular_expression>] [WHERE <tag_key> <operator> ['<tag_value>' | <regular_expression>]] [LIMIT_clause] [OFFSET_clause]
SHOW MEASUREMENTS [ON <database_name>] [WITH MEASUREMENT <regular_expression>] [WHERE <tag_key> <operator> ['<tag_value>' | <regular_expression>]] [LIMIT_clause] [OFFSET_clause]
> show measurements on test with measurement =~ /us*/
name: measurements
name
----
userInfo
> show measurements on test with measurement =~ /us*/
name: measurements
name
----
userInfo
2.4 删除measurement
两种方式,一个是把delete ,一个是drop
delete
> select * from userInfo
name: userInfo
time blog name userId
---- ---- ---- ------
1568467969678950115 ksksks blog 10
#删除
> delete from userInfo where time=1568467969678950115
> select * from userInfo
> select * from userInfo
name: userInfo
time blog name userId
---- ---- ---- ------
1568467969678950115 ksksks blog 10
#删除
> delete from userInfo where time=1568467969678950115
> select * from userInfo
- drop measurement
# 直接使用drop语句删除
> drop measurement userInfo
> show measurements
# 直接使用drop语句删除
> drop measurement userInfo
> show measurements
2.5修改
- 不同于mysql中的表,measurement是没有修改操作的,通过select重命名表名字
> select * into userBaseInfo from userInfo
name: result
time written
---- -------
0 3
#查询,可以指定多个表
> select * from userBaseInfo, userInfo
name: userBaseInfo
time blog name name_1 userId
---- ---- ---- ------ ------
1568468825672884073 ksksks blog 10
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2
name: userInfo
time blog name name_1 userId
---- ---- ---- ------ ------
1568468825672884073 ksksks blog 10
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2
> select * into userBaseInfo from userInfo
name: result
time written
---- -------
0 3
#查询,可以指定多个表
> select * from userBaseInfo, userInfo
name: userBaseInfo
time blog name name_1 userId
---- ---- ---- ------ ------
1568468825672884073 ksksks blog 10
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2
name: userInfo
time blog name name_1 userId
---- ---- ---- ------ ------
1568468825672884073 ksksks blog 10
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2
三、操作时区
3.1控制台时间格式调整
sql
influx -database 'csdn' -host '127.0.0.1' -port '8086'
> select * from k_LTCUSDT_1d limit 2;
name: k_LTCUSDT_1d
time close high low open times val vol
---- ----- ---- --- ---- ----- --- ---
1540137600000000000 53.3719 53.8838 53.3009 53.8829 1540137600000 15206364932.989 284001326.599202
1540224000000000000 53.6037 54.1713 53.101 53.3721 1540224000000 99040352876.3405 1850708709.04047
influx -database 'csdn' -host '127.0.0.1' -port '8086'
> select * from k_LTCUSDT_1d limit 2;
name: k_LTCUSDT_1d
time close high low open times val vol
---- ----- ---- --- ---- ----- --- ---
1540137600000000000 53.3719 53.8838 53.3009 53.8829 1540137600000 15206364932.989 284001326.599202
1540224000000000000 53.6037 54.1713 53.101 53.3721 1540224000000 99040352876.3405 1850708709.04047
时间的默认显示使用的是unix==时间戳==,执行命令precision rfc3339 设置时间格式,显示如下
sql
> precision rfc3339
> precision rfc3339
sql
> select * from k_LTCUSDT_1d where time < '2019-10-21T16:00:00Z' tz('Asia/Shanghai');
name: k_LTCUSDT_1d
time close high low open times val vol
---- ----- ---- --- ---- ----- --- ---
2018-10-22T00:00:00+08:00 53.3719 53.8838 53.3009 53.8829 1540137600000 15206364932.989 284001326.599202
2018-10-23T00:00:00+08:00 53.6037 54.1713 53.101 53.3721 1540224000000 99040352876.3405 1850708709.04047
2018-10-24T00:00:00+08:00 53.6751 54.1677 53.1067 53.6037 1540310400000 96476679269.7527 1794125395.53411
2018-10-25T00:00:00+08:00 53.3853 53.7586 53.1579 53.6751 1540396800000 90329008580.6363 1689769278.04597
2018-10-26T00:00:00+08:00 53.1379 53.8722 52.8806 53.3853 1540483200000 92913215997.9684 1742721113.09537
2018-10-27T00:00:00+08:00 52.7595 53.471 52.6461 53.138 1540569600000 90607109171.9869 1703499852.90586
2018-10-28T00:00:00+08:00 52.7163 53.0755 52.6711 52.7595 1540656000000 79761945897.4903 1510265152.98014
2018-10-29T00:00:00+08:00 48.6389 52.9532 47.4721 52.7163 1540742400000 73621147288.4907 1399612739.26006
> select * from k_LTCUSDT_1d where time < '2019-10-21T16:00:00Z' tz('Asia/Shanghai');
name: k_LTCUSDT_1d
time close high low open times val vol
---- ----- ---- --- ---- ----- --- ---
2018-10-22T00:00:00+08:00 53.3719 53.8838 53.3009 53.8829 1540137600000 15206364932.989 284001326.599202
2018-10-23T00:00:00+08:00 53.6037 54.1713 53.101 53.3721 1540224000000 99040352876.3405 1850708709.04047
2018-10-24T00:00:00+08:00 53.6751 54.1677 53.1067 53.6037 1540310400000 96476679269.7527 1794125395.53411
2018-10-25T00:00:00+08:00 53.3853 53.7586 53.1579 53.6751 1540396800000 90329008580.6363 1689769278.04597
2018-10-26T00:00:00+08:00 53.1379 53.8722 52.8806 53.3853 1540483200000 92913215997.9684 1742721113.09537
2018-10-27T00:00:00+08:00 52.7595 53.471 52.6461 53.138 1540569600000 90607109171.9869 1703499852.90586
2018-10-28T00:00:00+08:00 52.7163 53.0755 52.6711 52.7595 1540656000000 79761945897.4903 1510265152.98014
2018-10-29T00:00:00+08:00 48.6389 52.9532 47.4721 52.7163 1540742400000 73621147288.4907 1399612739.26006
sql
sh delete.sh field ProxyMarket "select * from k_BCHUSDT_1m where time < '2019-10-21T16:00:00Z' tz('Asia/Shanghai')"
sh delete.sh field ProxyMarket "select * from k_BCHUSDT_1m where time < '2019-10-21T16:00:00Z' tz('Asia/Shanghai')"