snippetsqlMinor
How to repair all indexes in a MySQL database?
Viewed 0 times
repairallindexesdatabasemysqlhow
Problem
My database got corrupted, and now the php app is throwing this error:
The error is not very useful, since it doesn't say what column/table is causing it.
Is there a way to regenerate FULLTEXT indexes on all columns in all tables within a specific database?
Thanks
Invalid query: Can't find FULLTEXT index matching the column listThe error is not very useful, since it doesn't say what column/table is causing it.
Is there a way to regenerate FULLTEXT indexes on all columns in all tables within a specific database?
Thanks
Solution
Perhaps you should look for all tables that have fulltext indexes
To individually remake all tables that have FULLTEXT indexes
If you are OK with the contents of
CAVEAT : All indexes are remade as well
SELECT DISTINCT table_schema,table_name
FROM information_schema.statistics
WHERE index_type='FULLTEXT';To individually remake all tables that have FULLTEXT indexes
REPAIR_SQL_SCRIPT=RemakeTables.sql
SQL="SELECT"
SQL="${SQL} CONCAT('ALTER TABLE ',db,'.',tb,' ENGINE=',eng,';')"
SQL="${SQL} FROM (SELECT A.table_schema db,A.table_name tb,B.engine eng"
SQL="${SQL} FROM (SELECT DISTINCT table_schema,table_name"
SQL="${SQL} FROM information_schema.statistics WHERE index_type='FULLTEXT') A"
SQL="${SQL} INNER JOIN information_schema.tables B"
SQL="${SQL} USING (table_schema,table_name)) AA"
mysql -uroot -ANe"${SQL}" > ${REPAIR_SQL_SCRIPT}
cat ${REPAIR_SQL_SCRIPT}If you are OK with the contents of
RemakeTables.sql, then execute it:mysql -uroot < ${REPAIR_SQL_SCRIPT}CAVEAT : All indexes are remade as well
Code Snippets
SELECT DISTINCT table_schema,table_name
FROM information_schema.statistics
WHERE index_type='FULLTEXT';REPAIR_SQL_SCRIPT=RemakeTables.sql
SQL="SELECT"
SQL="${SQL} CONCAT('ALTER TABLE ',db,'.',tb,' ENGINE=',eng,';')"
SQL="${SQL} FROM (SELECT A.table_schema db,A.table_name tb,B.engine eng"
SQL="${SQL} FROM (SELECT DISTINCT table_schema,table_name"
SQL="${SQL} FROM information_schema.statistics WHERE index_type='FULLTEXT') A"
SQL="${SQL} INNER JOIN information_schema.tables B"
SQL="${SQL} USING (table_schema,table_name)) AA"
mysql -uroot -ANe"${SQL}" > ${REPAIR_SQL_SCRIPT}
cat ${REPAIR_SQL_SCRIPT}mysql -uroot < ${REPAIR_SQL_SCRIPT}Context
StackExchange Database Administrators Q#52152, answer score: 3
Revisions (0)
No revisions yet.