Skip to content

Instantly share code, notes, and snippets.

@joostvanveen
Forked from molotovbliss/remove-table-prefixes.sql
Last active January 14, 2018 16:51
Show Gist options
  • Save joostvanveen/922a778a99c41ecf9301e8499f9f39a2 to your computer and use it in GitHub Desktop.
Save joostvanveen/922a778a99c41ecf9301e8499f9f39a2 to your computer and use it in GitHub Desktop.
Remove table prefixes MySQL
-- STEP 1: Set @database, @old_prefix and @new_prefix
-- STEP 2: Execute the query
-- STEP 3: Copy the string that was genereated by the query
-- STEP 4: Run the generated query to rename all tables
-- STEP 5: Use you Party Gun to make it rain!
SET SESSION group_concat_max_len = 999999999;
SET @database = "databasename";
SET @old_prefix = "ma2_";
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