欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

TiDB单机部署测试

程序员文章站 2022-07-13 09:08:13
...

安装:

  • Docker(17.06.0 及以上版本)
  • Docker Compose
  • Git
yum install docker
yum -y install epel-release
yum install docker-compose
yum install git

启动Docker

service docker start

下载tidb-docker-compose

git clone https://github.com/pingcap/tidb-docker-compose.git

创建并启动集群

cd tidb-docker-compose && docker-compose pull # Get the latest Docker images
docker-compose up -d

访问 PySpark并加载 TiSpark

向 TiDB 集群中加载一些样本数据:

$ docker-compose exec tispark-master bash
$ cd /opt/spark/data/tispark-sample-data
$ mysql -h tidb -u root < dss.ddl

当样本数据加载到 TiDB 集群之后,可以使用 docker-compose exec tispark-master /opt/spark/bin/pyspark 来访问 Spark。

$ docker-compose exec tispark-master /opt/spark/bin/pyspark

Python 2.7.14 (default, Dec 14 2017, 15:51:29) 
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /__ / .__/\_,_/_/ /_/\_\   version 2.1.1
      /_/

Using Python version 2.7.14 (default, Dec 14 2017 15:51:29)
SparkSession available as 'spark'.
from py4j.java_gateway import java_import
from pyspark.context import SparkContext

# We get a referenct to py4j Java Gateway
gw = SparkContext._gateway

java_import(gw.jvm, "org.apache.spark.sql.TiContext")

# Create a TiContext
ti = gw.jvm.TiContext(spark._jsparkSession)

# Map database
ti.tidbMapDatabase("TPCH_001", False, True)

# Query as usual
sql("select count(*) from customer").show()
+--------+
|count(1)|
+--------+
|    1500|
+--------+

转载于:https://my.oschina.net/aubao/blog/1858190