Rename a MySQL Schema (Sort Of)

To rename a schema (emulating the now-dropped RENAME DATABASE functionality):

 SELECT concat('RENAME TABLE oldSchema.',table_name, ' TO newSchema.',table_name, ';')
 FROM information_schema.TABLES
 WHERE table_schema='oldSchema';

Execute the resultant sql, then drop the now-empty old schema.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: