mysql 获取表的自增主键_采集MySQL数据库表自增主键使用情况

下面这个脚本是采集数据库自增主键水位的(遇到过业务主键设置过小,导致出问题的,因此我们必须将自增id的水位线监控起来)

IP_ADDR=$(/sbin/ip a|egrep '10.[0|1].[1-9]+.[1-9]+*' | awk '{print $2}'| cut -d '/' -f 1);

mysql -uroot -p123456 2>/dev/null -e "set @ip='$IP_ADDR';SELECT  @ip AS IP_ADDR,

curdate() AS INSERT_DATE ,

table_schema,

table_name,

column_name,

AUTO_INCREMENT,

POW(2, CASE data_type

WHEN 'tinyint'   THEN 7

WHEN 'smallint'  THEN 15

WHEN 'mediumint' THEN 23

WHEN 'int'       THEN 31

WHEN 'bigint'    THEN 63

END+(column_type LIKE '% unsigned'))-1 AS max_int

FROM information_schema.tables t

JOIN information_schema.columns c USING (table_schema,table_name)

WHERE

c.extra = 'auto_increment'

AND

t.TABLE_SCHEMA NOT IN ('information_schema','mysql', 'sys','test','performance_schema')

AND

t.auto_increment IS NOT NULL ; "

关于MySQL的采集脚本, 在prometheus的mysql_exporter的源代码里面,有很多,大家感兴趣的可以自己去看一下代码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值