
Ever installed Magento using a one click installer and forgot to remove the “wp_” prefix ?
Simple to remove your tables ? Nope ! pesky Foreign Key Constraints !
Try this code in your favourite MySql program. Please note running the resulting SQL code this will immediately delete all of your databases prefixed with “wp_” so if you are not sure back up !
Use at your own risk.!
1 2 3 |
SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_name LIKE 'mg_%'; |
Copy and paste the resultant code into your favourite MySQL GUI (Im a big fan of Navicat ) adding the below to the begining:
1 |
SET FOREIGN_KEY_CHECKS=0; |
Run the code and thats it !
Dont want to delete all your tables just rename them ?
What about rename all prefixed tables from ‘mg_tablename’ to ‘tablename’ ?
1 2 3 4 |
SELECT concat ('rename table ',table_name,' to ',REPLACE(table_name,'mg_',''),';') FROM information_schema.tables WHERE table_name like 'mg_%' and table_schema='your_database_name' |
Again copy and paste the resultant code into your favourite MySQL GUI adding this code to the begining:
1 |
SET FOREIGN_KEY_CHECKS=0; |
Warning running any resulting code could ruin your day proceed with caution.