内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

一個(gè)Shell小腳本精準(zhǔn)統(tǒng)計(jì)Mysql每張表的行數(shù)

前言

對(duì)于開發(fā)或者運(yùn)維人員來說,MySQL數(shù)據(jù)庫每張表的數(shù)量肯定是要了解下,有助于我們清理無用數(shù)據(jù)或者了解哪張表比較占用空間。
另外多次統(tǒng)計(jì)表的行數(shù),還能發(fā)現(xiàn)Mysql表的增量情況,能夠預(yù)測表未來會(huì)有多大的量。
廢話不多說,直接帶大家寫一個(gè)簡單的Shell小腳本

成都創(chuàng)新互聯(lián)是一家專業(yè)從事成都網(wǎng)站建設(shè)、做網(wǎng)站、網(wǎng)頁設(shè)計(jì)的品牌網(wǎng)絡(luò)公司。如今是成都地區(qū)具影響力的網(wǎng)站設(shè)計(jì)公司,作為專業(yè)的成都網(wǎng)站建設(shè)公司,成都創(chuàng)新互聯(lián)依托強(qiáng)大的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、營銷型網(wǎng)站建設(shè)及網(wǎng)站設(shè)計(jì)開發(fā)服務(wù)!

循環(huán)獲取數(shù)據(jù)庫名

直接上Shell代碼,show databases獲取所有的庫名。結(jié)果有一個(gè)我們不想要的,就是Database,這個(gè)grep -v掉,輕松獲取所有數(shù)據(jù)庫

[root@shijiangeit ~]# mysql -h 127.0.0.1 -uxxx -pxxx -e "show databases;" 2>/dev/null
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| shijiange          |
| test               |
| wordpress          |
+--------------------+
[root@shijiangeit ~]# mysql -h 127.0.0.1 -uxxx -pxxx -e "show databases;" 2>/dev/null |grep -v Database
information_schema
mysql
performance_schema
shijiange
test
wordpress

循環(huán)獲取所有表

有了庫信息,獲取所有表就簡單了,直接上Shell代碼。show tables獲取所有表名,其中Tables_in不需要,grep -v掉。

[root@shijiangeit ~]# for onedb in $(mysql -h 127.0.0.1 -uxxx -pxxx -e "show databases;" 2>/dev/null |grep -v Database);do
>   echo $onedb
>   mysql -h 127.0.0.1 -uxxx -pxxx $onedb -e "show tables" 2>/dev/null
> done
information_schema
+---------------------------------------+
| Tables_in_information_schema          |
+---------------------------------------+
| CHARACTER_SETS                        |
| COLLATIONS                            |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| COLUMNS                               |
| COLUMN_PRIVILEGES                     |
| ENGINES                               |
| EVENTS                                |
| FILES                                 |
| GLOBAL_STATUS                         |
| GLOBAL_VARIABLES                      |
| KEY_COLUMN_USAGE                      |

循環(huán)統(tǒng)計(jì)每張表的行數(shù)

取出庫名加表名,一個(gè)select count(1)統(tǒng)計(jì)表的行數(shù),循環(huán)統(tǒng)計(jì),直接上Shell代碼。

[root@shijiangeit ~]# for onedb in $(mysql -h 127.0.0.1 -uxxx -pxxx -e "show databases;" 2>/dev/null |grep -v Database);do
>   for onetab in $(mysql -h 127.0.0.1 -uxxx -pxxx $onedb -e "show tables" 2>/dev/null |grep -v 'Tables_in_');do
>     onetablength=$(mysql -h 127.0.0.1 -uxxx -pxxx $onedb -e "select count(1) from $onetab" 2>/dev/null |grep -v 'count')
>     echo -e "$onedb.$onetab\t$onetablength"
>   done
> done
information_schema.CHARACTER_SETS   40
information_schema.COLLATIONS   219
information_schema.COLLATION_CHARACTER_SET_APPLICABILITY    219
information_schema.COLUMNS  1789
information_schema.COLUMN_PRIVILEGES    0
shijiange.logincount    4
shijiange.member    0
shijiange.user  2097153
test.detect_servers 0
wordpress.wp_commentmeta    0
wordpress.wp_comments   0
wordpress.wp_links  0
wordpress.wp_options    156

變量化,腳本直接用

需要統(tǒng)計(jì)哪個(gè)Mysql,前面三個(gè)變量一改,立馬就能統(tǒng)計(jì)所有表的大小了。

mysqlhost=127.0.0.1
mysqluser=xxx
mysqlpassword=xxx

for onedb in $(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword -e "show databases;" 2>/dev/null |grep -v Database);do
  for onetab in $(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword $onedb -e "show tables" 2>/dev/null |grep -v 'Tables_in_');do
    onetablength=$(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword $onedb -e "select count(1) from $onetab" 2>/dev/null |grep -v 'count')
    echo -e "$onedb.$onetab\t$onetablength"
  done
done

想看哪張表的行數(shù)最多?

之前的腳本加個(gè) |sort -nrk 2|less 搞定,超實(shí)用的小腳本就這樣完成了

[root@shijiangeit ~]# for onedb in $(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword -e "show databases;" 2>/dev/null |grep -v Database);do
>   for onetab in $(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword $onedb -e "show tables" 2>/dev/null |grep -v 'Tables_in_');do
>     onetablength=$(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword $onedb -e "select count(1) from $onetab" 2>/dev/null |grep -v 'count')
>     echo -e "$onedb.$onetab\t$onetablength"
>   done
> done | sort -nrk 2
shijiange.user  2097153
information_schema.INNODB_BUFFER_PAGE   8191
performance_schema.events_waits_summary_by_thread_by_event_name 5320
information_schema.INNODB_BUFFER_PAGE_LRU   3453

分享題目:一個(gè)Shell小腳本精準(zhǔn)統(tǒng)計(jì)Mysql每張表的行數(shù)
轉(zhuǎn)載來源:http://www.rwnh.cn/article30/psgepo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、定制網(wǎng)站、網(wǎng)站營銷、外貿(mào)建站、小程序開發(fā)、網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營
乐清市| 阳春市| 西乌珠穆沁旗| 乌拉特后旗| 信宜市| 卢龙县| 福建省| 新津县| 乌恰县| 兴安县| 丰城市| 即墨市| 齐齐哈尔市| 苗栗市| 庐江县| 潞西市| 巴塘县| 额尔古纳市| 东乡县| 抚远县| 呼伦贝尔市| 上犹县| 晋州市| 屏南县| 蛟河市| 息烽县| 普兰店市| 沙湾县| 镇坪县| 西乌| 灵丘县| 徐水县| 荥经县| 高淳县| 新龙县| 格尔木市| 含山县| 南康市| 金山区| 连南| 中方县|