MySql, how can I export indexes from my development database to my production database?

前端 未结 6 757
南方客
南方客 2020-12-11 00:59

I\'ve been working on my development database and have tweaked its performance.

However, to my surprise I can\'t find a way to export the indexes to my production da

6条回答
  •  忘掉有多难
    2020-12-11 01:36

    Extending on @origo's answer. There is a case where i needed to extract the DDL for a bunch of indexes. This script does the job.

    source : https://rogerpadilla.wordpress.com/2008/12/02/mysql-export-indexes/

    SELECT
    CONCAT(
    'ALTER TABLE ' ,
    TABLE_NAME,
    ' ',
    'ADD ',
    IF(NON_UNIQUE = 1,
    CASE UPPER(INDEX_TYPE)
    WHEN 'FULLTEXT' THEN 'FULLTEXT INDEX'
    WHEN 'SPATIAL' THEN 'SPATIAL INDEX'
    ELSE CONCAT('INDEX ',
    INDEX_NAME,
    ' USING ',
    INDEX_TYPE
    )
    END,
    IF(UPPER(INDEX_NAME) = 'PRIMARY',
    CONCAT('PRIMARY KEY USING ',
    INDEX_TYPE
    ),
    CONCAT('UNIQUE INDEX ',
    INDEX_NAME,
    ' USING ',
    INDEX_TYPE
    )
    )
    ),
    '(',
    GROUP_CONCAT(
    DISTINCT
    CONCAT('', COLUMN_NAME, '')
    ORDER BY SEQ_IN_INDEX ASC
    SEPARATOR ', '
    ),
    ');'
    ) AS 'Show_Add_Indexes'
    FROM information_schema.STATISTICS
    WHERE TABLE_SCHEMA = 'PLEASE CHANGE HERE'
    GROUP BY TABLE_NAME, INDEX_NAME
    ORDER BY TABLE_NAME ASC, INDEX_NAME ASC;
    

提交回复
热议问题