TiDB 应急运维脚本,更加方便的管理TiDB集群
TiDB 应急运维脚本,更加方便的管理TiDB集群
使用方法
使用方法:[tidb@localhost ~]$ which tiup
~/.tiup/bin/tiup编辑脚本,MYSQL_PASSWD 和 PORT 根据实际替换
[tidb@localhost ~]$ vi ~/.tiup/bin/ti#version 1.1
#@author guanguanglei
##########################################################
#date 2023/06/14 version 1.0#!/bin/shMYSQL_USER=root
MYSQL_PASSWD=root
PORT=4000
TIDB_HOST=127.0.0.1
TIDB_CONNSTR="mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h$TIDB_HOST -P$PORT"
CLUSTER_NAME=gsc-quotation
case $1 in si)${TIDB_CONNSTR};;info)${TIDB_CONNSTR} -e "select * from information_schema.CLUSTER_INFO;";;user)${TIDB_CONNSTR} -e "select user,host from mysql.user;";;tidb)tiup cluster display $CLUSTER_NAME;;edit)tiup cluster edit-config $CLUSTER_NAME;;var)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "show variables like '%$2%';"else echo "please input second paramter with variable name"fi;;config)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "show config where name like '%$2%';"elseecho "please input config "fi;;list)${TIDB_CONNSTR} -e "select * from information_schema.cluster_processlist;";;listt)${TIDB_CONNSTR} -e "select * from information_schema.cluster_processlist order by time desc ;";;active)${TIDB_CONNSTR} -e "select * from information_schema.cluster_processlist where info is not null order by time desc \G;";;kill)${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e ' ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance;";;kstat)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e ' ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance where state='$2';"else echo "please input second paramter with session state"fi;;ksql)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e ' ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance where digest='$2';"elseecho "please input second paramter with sql digest"fi;;kid)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e ' ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance where id='$2';"elseecho "please input second paramter with connect id"fi;;klike)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e ' ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance where info like '%$2%';"elseecho "please input info like "fi;;plan)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select SUMMARY_BEGIN_TIME,SUMMARY_END_TIME,STMT_TYPE,SCHEMA_NAME,DIGEST,DIGEST_TEXT,TABLE_NAMES,INDEX_NAMES,QUERY_SAMPLE_TEXT,PLAN_DIGEST,PLAN from information_schema.statements_summary where digest='$2'\G;"elseecho "please input second paramter with sql digest"fi;;size)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e "SELECT TABLE_NAME,(DATA_LENGTH+INDEX_LENGTH)/1024/1024 mb,TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA='$2' AND TABLE_NAME='$3';"elseecho "please input second paramter with table owner and table_name"fi;;index)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e "show indexes from $2.$3;"elseecho "please input second paramter table_owner table_name"fi;; stats_meta)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e "show stats_meta where db_name='$2' table_name='$3';"elseecho "please input second paramter table_owner table_name"fi;; stats_histograms)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e "show stats_histograms where db_name='$2' and db_name='$3';"elseecho "please input second paramter table_owner table_name"fi;;dump)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e "select concat(' tiup dumpling -uroot -p -h --filetype csv -t 8 -o /tmp/backup -f ', '''', table_schema,'.',table_name,'''' ' --sql ''select * from ',table_name,'''') from tables where table_schema='$2' and table_name='$3';"elseecho "please input second paramter table_owner table_name"fi;;ctl)${TIDB_CONNSTR} -e "select concat('tiup ctl:',(select substring(version(),13,19)),' pd -u http://', (select INSTANCE from information_schema.cluster_info where TYPE='pd' limit 1),' -i') from dual;
";;*)echoecho "Usage: mib keyword [value1] ";echo echo " -----------------------------------------------------------------";echo " si -- login tidb database";echo " info -- show cluster info";echo " tidb -- tiup cluster display";echo " edit -- show cluster edit";echo " user -- list all user";echo " var -- show variables like ";echo " config -- show config where name like ";echo " list -- show processlist";echo " listt -- processlist order by time"; echo " active -- processlist order by time limit 10";echo " kill -- kill all session ";echo " kstat -- kill session state";echo " ksql -- kill sql session;"; echo " kid -- kill session id"; echo " klike -- kill info like "; echo " plan -- list sql plan"; echo " size -- get table size ";echo " index -- get on table index";echo " stats_meta -- getstats_meta on table";echo " stats_histograms -- get cloumn statistics on table";echo " ctl -- print tiup ctl command";
;;
esac
修改权限
[tidb@localhost ~]$ chmod 775 ~/.tiup/bin/ti
使用示例
1. 查看集群状态
ti tidb 2. 登录数据库
[tidb@localhost ~]$ ti si
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 820992
Server version: 5.7.25-TiDB-v4.0.13-1-g7eeeda700 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatibleCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MySQL [(none)]> 3.查看活跃会话
[tidb@localhost ~]$ ti active
*************************** 1. row ***************************
INSTANCE: xxxxxxxx :10080ID: 820997USER: rootHOST: 127.0.0.1DB: NULLCOMMAND: QueryTIME: 0STATE: 2INFO: select * from information_schema.cluster_processlist where info is not null order by time descDIGEST: 6140c4093c70debc9c729807414f36c32fad049daecf2d5655afd10a2374fae9MEM: 6
TxnStart: 08-10 15:22:29.866(443456461174472707)4. 登录pd
[root@vm10-2-103-65 ~]# ti ctl
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| concat('tiup ctl:',(select substring(version(),13,19)),' pd -u http://', (select INSTANCE from information_schema.cluster_info where TYPE='pd' limit 1),' -i') |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tiup ctl:v7.1.0 pd -u http://10.2.103.65:2379 -i |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@vm10-2-103-65 ~]# tiup ctl:v7.1.0 pd -u http://10.2.103.65:2379 -i
Starting component `ctl`: /root/.tiup/components/ctl/v7.1.0/ctl pd -u http://10.2.103.65:2379 -i
» 5. 查看参数
[root@vm10-2-103-65 ~]# ti var oom
+--------------------------------+--------+
| Variable_name | Value |
+--------------------------------+--------+
| tidb_enable_tmp_storage_on_oom | ON |
| tidb_mem_oom_action | CANCEL |
+--------------------------------+--------+查看config参数
root@vm10-2-103-65 ~]# ti config block-cache
+------+--------------------+-------------------------------------------+----------+
| Type | Instance | Name | Value |
+------+--------------------+-------------------------------------------+----------+
| tikv | 10.2.103.199:20160 | raftdb.defaultcf.block-cache-size | 317MiB |
| tikv | 10.2.103.199:20160 | raftdb.defaultcf.disable-block-cache | false |
| tikv | 10.2.103.199:20160 | raftdb.defaultcf.prepopulate-block-cache | disabled |
| tikv | 10.2.103.199:20160 | rocksdb.defaultcf.block-cache-size | 3971MiB |
| tikv | 10.2.103.199:20160 | rocksdb.defaultcf.disable-block-cache | false |
| tikv | 10.2.103.199:20160 | rocksdb.defaultcf.prepopulate-block-cache | disabled |6.查看执行计划
[root@vm10-2-103-65 ~]# ti plan 76069b6abc74fc855272108f656d4d1132948a55a3b12f66eaa4373648380d81
*************************** 1. row ***************************
SUMMARY_BEGIN_TIME: 2023-08-10 15:30:00SUMMARY_END_TIME: 2023-08-10 16:00:00STMT_TYPE: SelectSCHEMA_NAME: NULLDIGEST: 76069b6abc74fc855272108f656d4d1132948a55a3b12f66eaa4373648380d81DIGEST_TEXT: select * from `information_schema` . `cluster_processlist` where `info` is not ? order by time descTABLE_NAMES: information_schema.cluster_processlistINDEX_NAMES: NULLQUERY_SAMPLE_TEXT: select * from information_schema.cluster_processlist where info is not null order by time descPLAN_DIGEST: deabf06ff5a37585b637b6bc4ddf0bb2affc0aa92148953d10f678359c7cda69PLAN: id task estRows operator info actRows execution info memory diskSort_5 root 9990 information_schema.cluster_processlist.time:desc 1 time:41.9ms, loops:2 7.70 KB 0 Bytes└─TableReader_10 root 9990 data:Selection_9 1 time:41.9ms, loops:2, cop_task: {num: 2, max: 41.8ms, min: 41.5ms, avg: 41.6ms, p95: 41.8ms, rpc_num: 2, rpc_time: 83.2ms, copr_cache_hit_ratio: 0.00, max_distsql_concurrency: 2} 727 Bytes N/A└─Selection_9 cop[tidb] 9990 not(isnull(information_schema.cluster_processlist.info)) 0 N/A N/A└─TableFullScan_8 cop[tidb] 10000 table:CLUSTER_PROCESSLIST, keep order:false, stats:pseudo 0 N/A N/A7. kill 会话
[root@vm10-2-103-65 ~]# ti kid 716063544658887111
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| concat(concat('mysql -uroot -pM4Ab_d03%pQ27^1Xa# -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e ' ),concat('"kill tidb ',b.id,';"')) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mysql -uroot -pM4Ab_d03%pQ27^1Xa# -h 10.2.103.65 -P4000 -e "kill tidb 716063544658887111;" |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@vm10-2-103-65 ~]# mysql -uroot -pM4Ab_d03%pQ27^1Xa# -h 10.2.103.65 -P4000 -e "kill tidb 716063544658887111;" 8.常用命令
[root@vm10-2-103-65 ~]# ti Usage: mib keyword [value1] -----------------------------------------------------------------si -- login tidb databaseinfo -- show cluster infouser -- list all uservar -- show variables like config -- show config where name like list -- show processlistlistt -- processlist order by timeactive -- processlist order by time limit 10kill -- kill all session kstat -- kill session stateksql -- kill sql session;kid -- kill session idklike -- kill info like plan -- list sql plansize -- get table size index -- get on table indexstats_meta -- getstats_meta on tablestats_histograms -- get cloumn statistics on tablectl -- print tiup ctl command
相关文章:
TiDB 应急运维脚本,更加方便的管理TiDB集群
TiDB 应急运维脚本,更加方便的管理TiDB集群 使用方法 使用方法:[tidblocalhost ~]$ which tiup ~/.tiup/bin/tiup编辑脚本,MYSQL_PASSWD 和 PORT 根据实际替换 [tidblocalhost ~]$ vi ~/.tiup/bin/ti#version 1.1 #author guanguanglei ##…...

第二部分:AOP
一、AOP简介 AOP(Aspect Oriented Programming)面向切面编程,一种编程范式,指导开发者如何组织程序结构。 AOP是OOP(面向对象编程)的进阶版。 作用:在不改变原始设计的基础上为其进行功能增强。 spring理念&#x…...

分享一组天气组件
先看效果: CSS部分代码(查看更多): <style>:root {--bg-color: #E9F5FA;--day-text-color: #4DB0D3;/* 多云 */--cloudy-background: #4DB0D3;--cloudy-temperature: #E6DF95;--cloudy-content: #D3EBF4;/* 晴 */--sunny-b…...
微服务中RestTemplate访问其他服务返回值转换问题
背景: 接收一个springcloud项目,UI模块访问其他服务的接口,返回数据统一都是使用fastjson进行转换,但是新开发了几个新模块之后发现fastjson很多bug(各种内存溢出),但是很多地方已经重度依赖fa…...

Centos7.9上(离线)安装Gitlab
1、下载Gitlab的rpm安装包Index of /gitlab-ce/yum/el7/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror 2、安装rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm,如果依赖缺失,yum安装即可 3、vi /etc/gitlab/gitlab.rb 配置external_url&…...

pikachu中RCE出现乱码的解决的方案
exec “ping” 输入127.0.0.1 这种乱码的解决办法就是在pikachu/vul/rce/rce_ping.php目录里面的第18行代码 header("Content-type:text/html; charsetgbk");的注释打开即可。 BUT但是吧!又出现了其他的乱码!但是搞完这个再把它给注释掉就行了…...
airflow是什么
Airflow 简介 Airflow是一个基于有向无环图(DAG)的可编程、调度和监控的工作流平台,它可以定义一组有依赖的任务,按照依赖依次执行。airflow提供了丰富的命令行工具用于系统管控,而其web管理界面同样也可以方便的管控调度任务,并…...
训练用于序列分类任务的 RoBERTa 模型的适配器
介绍 NLP当前的趋势包括下载和微调具有数百万甚至数十亿参数的预训练模型。然而,存储和共享如此大的训练模型非常耗时、缓慢且昂贵。这些限制阻碍了 RoBERTa 模型开发更多用途和适应性更强的 NLP 技术,该模型可以从多个任务中学习并针对多个任务进行学习;在本文中,我们将重…...

Linux之awk判断和循环
echo zhaoy 70 72 74 76 74 72 >> score.txt echo wangl 70 81 84 82 90 88 >> score.txt echo qiane 60 62 64 66 65 62 >> score.txt echo sunw 80 83 84 85 84 85 >> score.txt echo lixi 96 80 90 95 89 87 >> score.txt把下边的内容写入到s…...

Django入门
Day1 django环境安装 创建虚拟环境 # step1 创建虚拟环境 python3 -m venv datawhale_django # step2 mac进入虚拟环境 source ./datawhale_django/bin/activate # step3 退出虚拟环境 deactivate安装包 pip3 install django pip3 install djangorestframework pip3 …...

uniapp 格式化时间刚刚,几分钟前,几小时前,几天前…
效果如图: 根目录下新建utils文件夹,文件夹下新增js文件,文件内容: export const filters {dateTimeSub(data) {if (data undefined) {return;}// 传进来的data必须是日期格式,不能是时间戳//将字符串转换成时间格式…...

JProfiler —CPU评测
当JProfiler测量方法调用的执行时间及其调用堆栈时,我们称之为“CPU评测”。这些数据以多种方式呈现。根据你试图解决的问题,其中一个或另一个演示将是最有帮助的。默认情况下不会记录CPU数据,您必须打开CPU记录才能捕获有趣的用例。 一、调…...
994. 腐烂的橘子
994. 腐烂的橘子(面试题打卡/前缀和/简单) 来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/rotting-oranges/ 题干: 在给定的 m x n 网格 grid 中,每个单元格可以有以下三个值之一:…...

Rx.NET in Action 第三章学习笔记
3 C#函数式编程思想 本章内容包括 将 C# 与函数式技术相结合使用委托和 lambda 表达式使用 LINQ 查询集合 面向对象编程为程序开发提供了巨大的生产力。它将复杂的系统分解为类,使项目更易于管理,而对象则是一个个孤岛,你可以集中精力分别处理…...

Windows11环境下VS2019调用Pytorch语义分割模型(C++版)
语义分割模型在训练时往往采用python脚本进行网络搭建和训练,并获得训练好的模型。为了提高效率方便整个工程项目部署,实际工程应用中通常希望使用C编程语言调用训练好的网络模型。查询大量网络资料并踩过无数坑后,经实际测试实现了在window1…...
Milkv Duo 以太网使用与配置
网络配置 使能网卡 使用ip link查看是否存在eth0网卡,若无使用如下命令使能网卡: ip link set eth0 up两次使用ip link确认网卡eth0已经使能。 配置IP、gws 本人设备连接到华为路由器下,故增加如下路由信息: ip route add d…...

bash: make: command not found
make之后报错信息如下:cd 对应的文件路径后 make 发现报错:bash: make: command not found 这个原因可能是没有安装make工具,也可能是安装了make之后,没有将make的文件路径添加到系统环境变量中 有没有安装make,可以使用Search Everything搜索是否有make…...

热点如何用于期刊写作——以chatGPT为例
交叉领域A,B 以自己为例子,A是教育 B是技术,我是教育技术学专业。 经验来源 知网关于GPT的140余篇专业论文的观察 截止至2023年8月14日15:35:45 学习每出现一个热点,如何应用于学术。 实践阅读发现 套路一:谈理论…...
IGV.js 的完全本地化运行探索
问题及解决方法 IGV.js 完全本地化是为了合规,不使用外网的情况下查看基因组。不联网需要下载 genomes.json 文件及其中的内容之外,还需要修改 igv.js本身,防止5s超时后才显示网页内容。修改的关键词是: genomes.json,改为本地的…...

网络安全渗透测试之靶场训练
NWES: 7月26号武汉地震检测中心遭受境外具有政府背景的黑客组织和不法分子的网络攻击。 目前网络攻击主要来自以下几种方式: DDOS:分布式拒绝服务攻击。通过制造大量无用的请求向目标服务器发起访问,使其因短时间内无法处理大量请求而陷入瘫痪。主要针对…...

龙虎榜——20250610
上证指数放量收阴线,个股多数下跌,盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型,指数短线有调整的需求,大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的:御银股份、雄帝科技 驱动…...

C++_核心编程_多态案例二-制作饮品
#include <iostream> #include <string> using namespace std;/*制作饮品的大致流程为:煮水 - 冲泡 - 倒入杯中 - 加入辅料 利用多态技术实现本案例,提供抽象制作饮品基类,提供子类制作咖啡和茶叶*//*基类*/ class AbstractDr…...

Spark 之 入门讲解详细版(1)
1、简介 1.1 Spark简介 Spark是加州大学伯克利分校AMP实验室(Algorithms, Machines, and People Lab)开发通用内存并行计算框架。Spark在2013年6月进入Apache成为孵化项目,8个月后成为Apache顶级项目,速度之快足见过人之处&…...
解锁数据库简洁之道:FastAPI与SQLModel实战指南
在构建现代Web应用程序时,与数据库的交互无疑是核心环节。虽然传统的数据库操作方式(如直接编写SQL语句与psycopg2交互)赋予了我们精细的控制权,但在面对日益复杂的业务逻辑和快速迭代的需求时,这种方式的开发效率和可…...
macOS多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用
文章目录 问题现象问题原因解决办法 问题现象 macOS启动台(Launchpad)多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用。 问题原因 很明显,都是Google家的办公全家桶。这些应用并不是通过独立安装的…...

ESP32 I2S音频总线学习笔记(四): INMP441采集音频并实时播放
简介 前面两期文章我们介绍了I2S的读取和写入,一个是通过INMP441麦克风模块采集音频,一个是通过PCM5102A模块播放音频,那如果我们将两者结合起来,将麦克风采集到的音频通过PCM5102A播放,是不是就可以做一个扩音器了呢…...

Cloudflare 从 Nginx 到 Pingora:性能、效率与安全的全面升级
在互联网的快速发展中,高性能、高效率和高安全性的网络服务成为了各大互联网基础设施提供商的核心追求。Cloudflare 作为全球领先的互联网安全和基础设施公司,近期做出了一个重大技术决策:弃用长期使用的 Nginx,转而采用其内部开发…...
【AI学习】三、AI算法中的向量
在人工智能(AI)算法中,向量(Vector)是一种将现实世界中的数据(如图像、文本、音频等)转化为计算机可处理的数值型特征表示的工具。它是连接人类认知(如语义、视觉特征)与…...

IT供电系统绝缘监测及故障定位解决方案
随着新能源的快速发展,光伏电站、储能系统及充电设备已广泛应用于现代能源网络。在光伏领域,IT供电系统凭借其持续供电性好、安全性高等优势成为光伏首选,但在长期运行中,例如老化、潮湿、隐裂、机械损伤等问题会影响光伏板绝缘层…...

视觉slam十四讲实践部分记录——ch2、ch3
ch2 一、使用g++编译.cpp为可执行文件并运行(P30) g++ helloSLAM.cpp ./a.out运行 二、使用cmake编译 mkdir build cd build cmake .. makeCMakeCache.txt 文件仍然指向旧的目录。这表明在源代码目录中可能还存在旧的 CMakeCache.txt 文件,或者在构建过程中仍然引用了旧的路…...