How to rename a MySQL database

Apparently long ago there was a rename database command but this was dropped for security reasons.

Now you have to do this:

for table in `mysql -u root -ppassword -s -N -e “use old_db;show tables from old_db;”`; do mysql -u root -ppassword -s -N -e “use old_db;rename table old_db.$table to new_db.$table;”; done;

Note:

Remember to create new_db first

Reference:

https://stackoverflow.com/questions/67093/how-do-i-quickly-rename-a-mysql-database-change-schema-name

Tags

Share this article

Leave a Reply

Your email address will not be published.

Scroll to Top