mysql- sql-mode 資料庫大小查詢

來源:互聯網
上載者:User

標籤:mysql_sql_mode --資料庫大小查詢

Mysql ---查看資料庫和表大小


查看mysql資料庫大小的四種辦法,分別有以下四種:

第一種:進去指定schema 資料庫(存放了其他的資料庫的資訊)

use information_schema


第二種:查詢所有資料的資料檔案和索引檔案 大小

select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data_size from information_schema.TABLES;

select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data_size,

CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),‘MB‘) AS index_size

from information_schema.TABLES;


第三種:查看指定資料庫的資料檔案和索引檔案 的大小,比如說:資料庫test

select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data_size,

CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),‘MB‘) AS index_size

from information_schema.TABLES where table_schema=‘test‘;  


第四種:查看指定資料庫的表的資料檔案和作引檔案 大小,比如說:資料庫test 中am21表

select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data_size,

CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),‘MB‘) AS index_size

 from information_schema.TABLES where table_schema=‘test‘ and table_name=‘am21‘;


綜合查詢在   5.7不適用   是因為sql_mode未設定

SELECT TABLE_SCHEMA, CONCAT(TRUNCATE(SUM(data_length)/1024/1024,2),‘ MB‘) AS data_size,

CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),‘MB‘) AS index_size

FROM information_schema.tables;

GROUP BY TABLE_SCHEMA

ORDER BY data_length DESC;


報錯如下

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘GROUP BY TABLE_SCHEMA

ORDER BY data_length DESC‘ at line 1


解決辦法---  echo "sql_mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"" >> /etc/my.cnf   重啟mysql,再次執行

查看sql_mode

mysql -uroot -psunfuzhou -e "SHOW VARIABLES LIKE ‘SQL_MODE‘;"

設定sql_mode

臨時設定sql_mode

mysql -uroot -psunfuzhou -e "SET  sql_mode=‘NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION ‘"

全域設定sql_mode

mysql -uroot -psunfuzhou -e "SET global  sql_mode=‘NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION ‘"

SET @@GLOBAL.sql_mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";

 

SELECT TABLE_SCHEMA, CONCAT(TRUNCATE(SUM(data_length)/1024/1024,2),‘ MB‘) AS data_size,

CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),‘MB‘) AS index_size

FROM information_schema.tables;

GROUP BY TABLE_SCHEMA

ORDER BY data_length DESC;






650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />


本文出自 “linux營運” 部落格,請務必保留此出處http://sunfuzhou.blog.51cto.com/8603214/1969687

mysql- sql-mode   資料庫大小查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.