TiDB 是开源分布式关系型数据库,是一款同时支持在线事务处理与在线分析处理 (Hybrid Transactional and Analytical Processing, HTAP)的融合型分布式数据库产品,具备水平扩容或者缩容、金融级高可用、实时 HTAP、云原生的分布式数据库、兼容 MySQL 5.7 协议和 MySQL 生态等重要特性。目标是为用户提供一站式 OLTP (Online Transactional Processing)、OLAP (Online Analytical Processing)、HTAP 解决方案。TiDB 适合高可用、强一致要求较高、数据规模较大等各种应用场景。

本文目标

  • 初步了解TiDB
  • 使用TiUP在单机上模拟生产环境搭建TiDB集群步骤
  • 基本使用

初步了解TiDB

  • TiDB是 开源的 分布式的 关系型的 数据库
  • TiDB兼容 MySQL 5.7 协议
  • TiDB具备水平扩容和缩容
  • 官网:https://pingcap.com/

使用TiUP在单机上模拟生产环境搭建TiDB集群步骤

官方快速入门教程:https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb
18年10月写的一篇搭建TiDB的教程:https://4xx.me/archives/67.html

1. TiUP是一个集群管理工具,推荐部署在中控机

2. 准备一台部署主机,推荐安装 CentOS 7.3 及以上版本。(可以和中控机在一起)

3. 下载并安装 TiUP

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
## 重新声明全局环境变量
source .bash_profile
## 确认 TiUP 工具是否安装
which tiup
## 安装 TiUP cluster 组件
tiup cluster
## 更新 TiUP cluster 组件至最新版本
tiup update --self && tiup update cluster

4. 新建一个配置文件 topology.yaml。ip改成需要部署的机器的ip,注意ssh端口

## Global variables are applied to all deployments and used as the default value of
## the deployments if a specific deployment value is missing.
global:
 user: "tidb"
 ssh_port: 22
 deploy_dir: "/data/tidb-deploy"
 data_dir: "/data/tidb-data"

## Monitored variables are applied to all the machines.
monitored:
 node_exporter_port: 9100
 blackbox_exporter_port: 9115

server_configs:
 tidb:
   log.slow-threshold: 300
 tikv:
   readpool.storage.use-unified-pool: false
   readpool.coprocessor.use-unified-pool: true
 pd:
   replication.enable-placement-rules: true
 tiflash:
   logger.level: "info"

pd_servers:
 - host: 192.168.137.13

tidb_servers:
 - host: 192.168.137.13

tikv_servers:
 - host: 192.168.137.13
   port: 20160
   status_port: 20180

monitoring_servers:
 - host: 192.168.137.13

5. 执行集群部署命令

### 查看tidb版本列表
tiup list tidb
### tidb-test 为集群名称,v4.0.4 当前安装的版本
tiup cluster deploy tidb-test v4.0.4 ./topology.yaml --user root -p
### 按照引导,输入”y”及 root 密码,来完成部署

6. 启动集群

### tidb-test 为集群名称
tiup cluster start tidb-test

7. 查看集群的拓扑结构和状态

tiup cluster display tidb-test

8. 访问web监控后台,默认账号root,密码空

http://192.168.137.13:2379/dashboard/#/signin

QQ截图20200807154704.png

基本使用

1. 使用 Navicat Premium 15注册版 连接数据库,默认端口4000,账号root,密码空

QQ截图20200807155010.png

QQ截图20200807154912.png

2. 修改或设置密码

## set password for 账号=password('新密码');
set password for root=password('root');