-
-
Save victordit/9e6ef5167dcb73d8a487138911ffe106 to your computer and use it in GitHub Desktop.
Remove table prefixes MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set @database, @old_prefix and @new_prefix (if you want a different prefix instead of removing) | |
# Execute the Generated SQL Query this generates to rename all tables found with prefix. | |
SET SESSION group_concat_max_len = 999999999; | |
SET @database = "databasename"; | |
SET @old_prefix = "mgn_"; | |
SET @new_prefix = ""; | |
SELECT GROUP_CONCAT("RENAME TABLE ", TABLE_NAME, " TO ", replace(TABLE_NAME, @old_prefix, @new_prefix),'; ' separator '') | |
FROM information_schema.TABLES WHERE TABLE_SCHEMA = @database AND TABLE_NAME LIKE CONCAT(@old_prefix, '%'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment