0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

一括でinnodbテーブルを圧縮するAlterコマンドを生成するSQL

Last updated at Posted at 2018-09-06

Mysql運用し始めて、DISK容量が足らなくなった時に使ってみてください。
大体テーブル容量が半分になるので、

SELECT
`TABLES`.TABLE_SCHEMA,
`TABLES`.TABLE_NAME,
`TABLES`.ROW_FORMAT,
CONCAT("ALTER TABLE `",`TABLES`.TABLE_SCHEMA,"`.`",`TABLES`.TABLE_NAME,"` ROW_FORMAT = COMPRESSED;"),
`TABLES`.*
FROM
information_schema.`TABLES`
WHERE
`TABLES`.ROW_FORMAT != "Compressed"
AND
`TABLES`.TABLE_SCHEMA NOT IN ("information_schema","performance_schema","mysql","sys")
AND
`TABLES`.ENGINE = "InnoDB"
AND
`TABLES`.CREATE_OPTIONS not like "%COMPRESSION%"

system schema とmyisamは除外してます。
pt-online-schema-changeとかとセットに使うとよいかも。

pt-online-schema-changeを安全につかう
http://strsk.hatenablog.com/entry/2014/12/19/003044

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?