How To Rename Database in Mysql?

Well you don’t.

As ‘RENAME’ was thought as bad idea hence not available in later version of mysql.

Easiest way is to dump database and import into new.

But alternatively,

Use Linux Command line:

> TABLES=`mysql -u*** -p*** db_name -sNe ‘show tables’;`

> for table in $TABLES; do mysql -u *** -p*** -s -N -e “rename table db_name.$table to new_db_name.$table”; done;

Issues I know:

  • It wouldn’t work for view and procs and fucntions.
  • It will fail if triggers are used.
This entry was posted in Mysql. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>