欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

tiDB笔记

时间:2023-08-23

docker-compose安装参考地址GitHub链接

$ git clone https://github.com/pingcap/tidb-docker-compose.git$ cd tidb-docker-compose && docker-compose pull # Get the latest Docker images$ sudo setenforce 0 # only on Linux$ docker-compose up -ddocker-compose ps # 查看docker-compose启动的容器

启动后可在浏览器打开以下:
grafana: localhost:3000
localhost:8010
可像连接MySQL一样连接tiDB,端口是4000

create database if not exists smap_db;show databases;drop database smap_db;use smap_db;show tables;create table if not exists person(id int(11),name varchar(30),create_at date);show create table person;drop table person;show index from person; -- 查看person表索引create index create_at_idx on person(create_at);drop index create_at_idx on person;create unique index name_idx on person(name);insert into person values(1,'n1','2022-02-02');select * from person;create user 'user_ti'@'0.0.0.0' identified by '123456';grant select on smap_db.* to 'user_ti'@'0.0.0.0';show grants for 'user_ti'@'0.0.0.0';show grants;drop user 'user_ti'@'0.0.0.0';select version();select now(); -- 2022-02-02 06:52:06update person set name='nn' where id = 1;select * from person;set @@tidb_snapshot='2022-02-02 06:52:06'; -- 设置后当前会话则查询的是此时间点前的历史数据select @@tidb_snapshot;select * from person;set @@tidb_snapshot='';

## 将dss.ddl导入到tidb,导入后刷新会发现多了一个数据库TPCH_001D:xxlearntiDBtidb-docker-compose>docker-compose exec tispark-master bashbash-4.4# cd /opt/spark/data/tispark-sample-data/bash-4.4# lscustomer.tbl dss.ddl lineitem.tbl nation.tbl orders.tbl part.tbl partsupp.tbl region.tbl sample_data.sh supplier.tblbash-4.4# mysql -h tidb -P 4000 -u root < dss.ddlbash-4.4#

# 启动spark shell查询数据D:xxlearntiDBtidb-docker-compose>docker-compose exec tispark-master /opt/spark/bin/spark-shellscala> import org.apache.spark.sql.TiContextscala> val ti=new TiContext(spark)scala> ti.tidbMapDatabase("TPCH_001")scala> spark.sql("select count(*) from CUSTOMER").show

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。