MySQL 如何获取mysql表中列的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21772205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get size of column in mysql table
提问by user1446650
I'm trying to find out the exact size of one column within a table. PHPMyAdmin doesn't show size of columns, only the tables.
我试图找出表格中一列的确切大小。PHPMyAdmin 不显示列的大小,只显示表。
Any way I can get the size of the column?
有什么办法可以得到列的大小?
Thankyou
谢谢
回答by tim berspine
If you want to find out the size of column=COLUMN_NAME from table=TABLE_NAME, you can always run a query like this:
如果您想从 table=TABLE_NAME 中找出 column=COLUMN_NAME 的大小,您可以随时运行如下查询:
SELECT sum(char_length(COLUMN_NAME))
FROM TABLE_NAME;
Size returned is in bytes. If you want it in kb, you could just divide it by 1024, like so:
返回的大小以字节为单位。如果您想要以 kb 为单位,您可以将其除以 1024,如下所示:
SELECT sum(char_length(COLUMN_NAME))/1024
FROM TABLE_NAME;
回答by Vignesh Kumar A
SELECT column_name,
character_maximum_length
FROM information_schema.columns
WHERE table_schema = Database()
AND -- name of your database
table_name = 'turno'
AND -- name of your table
column_name = 'nombreTurno' -- name of the column
INFORMATION_SCHEMA.COLUMNS
INFORMATION_SCHEMA.COLUMNS
If you wanna Whole Table size then use this
如果你想要整桌大小,那么使用这个
SELECT table_name AS "Tables",
Round(( ( data_length + index_length ) / 1024 / 1024 ), 2) "Size in MB"
FROM information_schema.tables
WHERE table_schema = "$db_name"
ORDER BY ( data_length + index_length ) DESC;
Edit
编辑
SELECT column_name,
character_maximum_length
FROM information_schema.columns
WHERE table_schema = 'websi_db1'
AND table_name = 'thread'
AND column_name = 'title'
回答by insaner
If you are doing this from a script, you can run this after you have established a connection (and hence the database is already selected):
如果您从脚本执行此操作,则可以在建立连接后运行此操作(因此已选择数据库):
SELECT character_maximum_length
FROM information_schema.columns
WHERE table_name = ? AND column_name = ?
Replace the ?'s with the name of your table and the name of your column, respectively.
分别用表名和列名替换 ?'s。