TiDB的连接&目录结构

发布时间 2023-08-20 21:38:50作者: UncleDBA


TiDB 完全兼容MySQL 5.7链接协议,所以可以使用mysql 客户端来连接,默认端口是 4000

[root@svr101 ~]# mysql -uroot -h192.168.31.102 -P4000 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 419
Server version: 5.7.25-TiDB-v6.1.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


TiDB 同样支持MySQL show 命令 和 列竖式显示 \G :
root@svr01 21:24: [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| INFORMATION_SCHEMA |
| METRICS_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql |
| test |
| tpcc |
+--------------------+
6 rows in set (0.00 sec)

root@svr01 21:27: [(none)]> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.1.0
Edition: Community
Git Commit Hash: 1a89decdb192cbdce6a7b0020d71128bc964d30f
Git Branch: heads/refs/tags/v6.1.0
UTC Build Time: 2022-06-05 05:15:11
GoVersion: go1.18.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

链接TiDB cloud 实例时,需要先设置 traffic filter(白名单),然后使用mysql 链接即可
TiDB cloud 也提供 SQL shell 链接到集群。

 

TiDB文件目录
不同类型节点数据目录一样,但是大致规划是一致的,分为两大类
服务安装目录 /tidb-deploy/<service-port> /*
和数据存放目录 /tidb-data/*

/tidb-deploy/tidb-4000/{bin,conf,log,scripts}
/tidb-deploy/tikv-20160/{bin,conf,log,scripts}
/tidb-deploy/pd-2379/{bin,conf,log,scripts}
/tidb-deploy/tiflash-9000/{bin,conf,log,scripts}

TiDB 节点除了监控相关的数据,并没有存储数据库相关的数据。
因为它只负责建立链接,接受请求,生成执行计划,结合PD的元数据,调用Tikv API.
将操作结果返回给客户端,它是无状态的,不需要持久化数据。

[root@svr103 ~]# ll /tidb-data/
total 4
drwxr-xr-x 2 tidb tidb 35 Aug 20 21:06 alertmanager-9093
drwxr-xr-x 2 tidb tidb 6 Aug 9 23:19 monitor-9100
drwxr-xr-x 14 tidb tidb 4096 Aug 20 21:00 prometheus-9090

Tikv 节点是实际存储数据库的节点,其数据以K-V形式组织在region内,以行的形式存储记录。
[root@svr107 ~]# ll /tidb-data/tikv-20160/
total 1066424
drwxr-xr-x 2 tidb tidb 4096 Aug 20 20:51 db
drwxr-xr-x 4 tidb tidb 33 Aug 20 20:51 import
-rw-r--r-- 1 tidb tidb 20450 Aug 19 16:06 last_tikv.toml
-rw-r--r-- 1 tidb tidb 0 Aug 20 20:50 LOCK
-rw-r--r-- 1 tidb tidb 0 Aug 9 23:22 raftdb.info
drwxr-xr-x 2 tidb tidb 4096 Aug 18 22:27 raft-engine
-rw-r--r-- 1 tidb tidb 18243555 Aug 18 22:32 rocksdb.info
drwxr-xr-x 2 tidb tidb 6 Aug 19 14:32 snap
-rw-r--r-- 1 tidb tidb 1073741824 Aug 20 20:50 space_placeholder_file

PD 节点存储的是数据库元数据,主要包括Tikv节点内KV的分布,节点状态等信息
[root@svr104 ~]# ll /tidb-data/pd-2379/
total 0
drwxr-xr-x 2 tidb tidb 122 Aug 20 20:50 hot-region
drwx------ 4 tidb tidb 29 Aug 20 20:50 member
drwxr-xr-x 2 tidb tidb 140 Aug 20 20:50 region-meta

tiflash 节点也是存储数据库的节点,以列的形式存储记录,用来应对OLAP业务。
[root@svr110 ~]# ll /tidb-data/tiflash-9000/
total 8
drwxr-xr-x 35 tidb tidb 4096 Aug 20 19:10 data
drwxr-xr-x 2 tidb tidb 6 Aug 9 23:22 flags
drwxr-xr-x 7 tidb tidb 179 Aug 20 20:51 flash
drwxr-xr-x 2 tidb tidb 6 Aug 9 23:22 format_schemas
drwxr-xr-x 6 tidb tidb 91 Aug 19 16:05 kvstore
drwxr-xr-x 7 tidb tidb 144 Aug 20 19:10 metadata
drwxr-xr-x 6 tidb tidb 56 Aug 19 16:05 page
-rw-r--r-- 1 tidb tidb 58 Aug 20 20:51 status
drwxr-xr-x 2 tidb tidb 6 Aug 9 23:22 tmp
drwxr-xr-x 2 tidb tidb 6 Aug 9 23:22 user_files