统计MySQL数据库中每个库的每个表的行数
1、编辑脚本
#!/bin/bash # 设置MySQL连接信息 user="your_username" password="your_password" host="localhost" # 输出文件名 output_file="table_row_counts.txt" # 创建或清空输出文件 > "$output_file" # 获取所有数据库列表 databases=$(mysql -u"$user" -p"$password" -h"$host" -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)") # 遍历每个数据库 for db in $databases; do # 获取数据库中的所有表 tables=$(mysql -u"$user" -p"$password" -h"$host" -e "USE $db; SHOW TABLES;" | grep -v "Tables_in") # 遍历每个表并获取行数 for table in $tables; do row_count=$(mysql -u"$user" -p"$password" -h"$host" -e "USE $db; SELECT COUNT(*) FROM $table;" | grep -v "COUNT") # 将结果追加到输出文件 echo "Database: $db, Table: $table, Row count: $row_count" >> "$output_file" done done echo "Table row counts saved in $output_file"
2、执行脚本
./count_rows.sh
这将统计每个库中每个表的行数,并将结果保存到table_row_counts.txt文件中。
喜欢请赞赏一下啦^_^
微信赞赏

支付宝赞赏

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2020-05-19 oracle11g-关闭日志审计
2020-05-19 在线剪辑歌曲