MySQL OPTIMIZE all tables?

前端 未结 14 2144
迷失自我
迷失自我 2020-12-04 04:57

MySQL has an OPTIMIZE TABLE command which can be used to reclaim unused space in a MySQL install. Is there a way (built-in command or common stored procedure) to run this o

14条回答
  •  天涯浪人
    2020-12-04 05:24

    You can optimize/check and repair all the tables of database, using mysql client.

    First, you should get all the tables list, separated with ',':

    mysql -u[USERNAME] -p[PASSWORD] -Bse 'show tables' [DB_NAME]|xargs|perl -pe 's/ /,/g'
    

    Now, when you have all the tables list for optimization:

    mysql -u[USERNAME] -p[PASSWORD] -Bse 'optimize tables [tables list]' [DB_NAME]
    

提交回复
热议问题