cqlsh timezone设置

CQLSH时区配置
本文详细介绍如何在Scylla/Cassandra中通过cqlsh设置本地时区显示时间戳,包括安装pytz库、配置cqlshrc文件及执行配置的方法。

cqlsh timezone设置

Scylla/Cassandra 的timestamp 读取时间会默认使用UTC,cqlsh查询的时候默认时区默认+0,
如要在使用cqlsh的时候,查询时间戳按照本时区显示,需要如下设置:
1.安装依赖

pytz
By default, cqlsh displays all timestamps with a UTC timezone. To support display of timestamps with another timezone, the pytz library must be installed. See the timezone option in cqlshrc for specifying a timezone to use.

sudo pip install pytz

2.新建或在已有的cqlshrc文件中添加如下配置

[ui]
timezone = Asia/Shanghai

具体需要的时区可以在这里查阅:https://docs.djangoproject.com/zh-hans/2.2/_modules/pytz/

3.cqlsh执行配置–cqlshrc

cqlsh --cqlshrc=./cqlshrc

通过查询timestamp一列:
操作之前:

[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cassandra@cqlsh>select timestamp  from user_action.test where device_id='c64dc532'
 timestamp
--------------------------
 2019-04-21 22:11:55+0000

操作之后:

[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cassandra@cqlsh> select timestamp  from user_action.realtime_user_action where  device_id = 'c64dc532';
 timestamp
--------------------------
 2019-04-22 06:11:55+0800

可以观察到时区+08。如果需要以Driver的方式进行时区转换就是对应Driver API的事情啦。

在spring boot项目启动时,报错如下: Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cassandraSession' threw exception; nested exception is java.lang.IllegalStateException: Since you provided explicit contact points, the local DC must be explicitly set (see basic.load-balancing-policy.local-datacenter in the config, or set it programmatically with SessionBuilder.withLocalDatacenter). Current contact points are: Node(endPoint=/127.0.0.1:9042, hostId=5fa2e127-96a3-4bc7-96d0-42a3de83e831, hashCode=3b13c84f)=datacenter1. Current DCs in this cluster are: datacenter1 yaml文件配置如下所示 spring: profiles: active: mysql # 默认使用MySQL配置 grpc: server: port: 9091 system: max-user-limit: 10 management: endpoints: web: exposure: include: metrics # ==================== MySQL 配置 ==================== --- spring: config: activate: on-profile: mysql datasource: url: jdbc:mysql://localhost:3306/springbootdemo?useSSL=false&serverTimezone=UTC&characterEncoding=utf8 username: root password: 159357 driver-class-name: com.mysql.cj.jdbc.Driver jpa: show-sql: true hibernate: ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect format_sql: true jdbc: lob: non_contextual_creation: true # ==================== Cassandra 配置 ==================== --- spring: config: activate: on-profile: cassandra # 激活cassandra profile时使用此配置 data: cassandra: keyspace-name: my_database # 替换为实际keyspace名称 local-datacenter: datacenter1 contact-points: localhost # Cassandra节点地址 port: 9042 # 默认Cassandra端口 compression: none connection: connect-timeout: 10s init-query-timeout: 10s
最新发布
08-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值