patternsqlMinor
mysql: find column data size on disk
Viewed 0 times
diskcolumnsizemysqlfinddata
Problem
I have fairly large
Table size is somewhat 16GB.
I need to know if clearing this column in old records helps to keep table small
I can retrieve table wise
Is there a way to find
MyISAM table with longtext field in itTable size is somewhat 16GB.
I need to know if clearing this column in old records helps to keep table small
I can retrieve table wise
Data_length using information_schema.tablesIs there a way to find
Data_length just for this one column?Solution
Here is how you find the sum of the lengths the LONGTEXT column of all rows
Once you delete the rows you want, just compress the file
You can do it in a single command
or in stages
Give it a Try !!!
SELECT SUM(field_length) TotalFieldLength FROM
(SELECT LENGTH(LongTextColumnName) field_length FROM mydb.mytable) A;Once you delete the rows you want, just compress the file
You can do it in a single command
OPTIMIZE TABLE mydb.mytable;or in stages
CREATE TABLE mydb.mytablenew LIKE mydb.mytable;
ALTER TABLE mydb.mytablenew DISABLE KEYS;
INSERT INTO mydb.mytablenew SELECT * FROM mydb.mytable;
ALTER TABLE mydb.mytablenew ENABLE KEYS;
ALTER TABLE mydb.mytable RENAME mydb.mytablezap;
ALTER TABLE mydb.mytablenew RENAME mydb.mytable;
DROP TABLE mydb.mytablezap;
ANALYZE TABLE mydb.mytable;Give it a Try !!!
Code Snippets
SELECT SUM(field_length) TotalFieldLength FROM
(SELECT LENGTH(LongTextColumnName) field_length FROM mydb.mytable) A;OPTIMIZE TABLE mydb.mytable;CREATE TABLE mydb.mytablenew LIKE mydb.mytable;
ALTER TABLE mydb.mytablenew DISABLE KEYS;
INSERT INTO mydb.mytablenew SELECT * FROM mydb.mytable;
ALTER TABLE mydb.mytablenew ENABLE KEYS;
ALTER TABLE mydb.mytable RENAME mydb.mytablezap;
ALTER TABLE mydb.mytablenew RENAME mydb.mytable;
DROP TABLE mydb.mytablezap;
ANALYZE TABLE mydb.mytable;Context
StackExchange Database Administrators Q#12001, answer score: 4
Revisions (0)
No revisions yet.