MySQL OPTIMIZE all tables?

前端 未结 14 2132
迷失自我
迷失自我 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:31

    From phpMyAdmin and other sources you can use:

    SET SESSION group_concat_max_len = 99999999;
    SELECT GROUP_CONCAT(concat('OPTIMIZE TABLE `', table_name, '`;') SEPARATOR '') AS O
    FROM INFORMATION_SCHEMA.TABLES WHERE 
    TABLE_TYPE = 'BASE TABLE'
    AND table_name!='dual'
    AND TABLE_SCHEMA = ''
    

    Then you can copy & paste the result to a new query or execute it from your own source. If you don't see the whole statement:

提交回复
热议问题