Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Last active May 31, 2021 11:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save molotovbliss/8fa6cd289a000f0abe53 to your computer and use it in GitHub Desktop.
Save molotovbliss/8fa6cd289a000f0abe53 to your computer and use it in GitHub Desktop.
Remove table prefixes MySQL
# 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