Skip to content

Instantly share code, notes, and snippets.

@glafarge
Created June 13, 2018 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glafarge/76fc615928530e3d84b3106c43be095a to your computer and use it in GitHub Desktop.
Save glafarge/76fc615928530e3d84b3106c43be095a to your computer and use it in GitHub Desktop.
Change all tables prefixes in database at once
SET @database = "database_name";
SET @old_prefix = "old_prefix_";
SET @new_prefix = "new_prefix_";
SELECT
concat(
"RENAME TABLE ",
TABLE_NAME,
" TO ",
replace(TABLE_NAME, @old_prefix, @new_prefix),
';'
) AS "SQL"
FROM information_schema.TABLES WHERE TABLE_SCHEMA = @database;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment