Skip to content

Instantly share code, notes, and snippets.

@daubac402
Created November 12, 2020 08:39
Show Gist options
  • Save daubac402/fa1f5ad3762f5de5d2c09296f9a08503 to your computer and use it in GitHub Desktop.
Save daubac402/fa1f5ad3762f5de5d2c09296f9a08503 to your computer and use it in GitHub Desktop.
Prepare to OPTIMIZE MySQL tables
1. Check current defrag status:
SQL> select table_name,round(data_length/1024/1024) as data_length_mb, round(data_free/1024/1024) as data_free_mb from information_schema.tables order by data_free_mb;
2. Optimize one table or multi:
SQL> OPTIMIZE TABLE your_table_name;
SQL> OPTIMIZE TABLE your_table_name1, your_table_name2, your_table_name3;
(or)
Optimize all of your tables in "your_database":
(from bash, not in mysql client bash)
# mysqlcheck -o your_database -u your_user -pYOUR_PASSWORD
(or even)
Optimize all of your databases:
# mysqlcheck -o --all-databases -u your_user -pYOUR_PASSWORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment