Rename database option when renaming Virtual Servers

When renaming a Virtual Server, the databases within it aren't renamed.

That may be what some folks want, but others are interested in renaming the database to match.

In Server Configuration -> Change domain name, would it be possible to add an option to that list, asking if they would like to rename the database(s)?

Status: 
Active

Comments

This is actually pretty tricky, for two reasons :

  1. MySQL doesn't have any way to rename a database. It would have to be backed up to a file, deleted, re-created and restored.

  2. Any scripts that are using the old DB name will be broken by a rename.

Renaming a live MySQL database is easy if it does not contain any views or stored procedures. The steps are:


mysql -e "CREATE DATABASE \`new_database\`;"
for table in `mysql -B -N -e "SHOW TABLES;" old_database`
do
mysql -e "RENAME TABLE \`old_database\`.\`$table\` to \`new_database\`.\`$table\`"
done
# Drop the old database once the new one is tested / confirmed working
#mysql -e "DROP DATABASE \`old_database\`;"

I just ran into this. It failed to change the database name accordingly when I changed a virtual server.

In my case, it shows that it is missing some information when changing the name.

As an example, it shows: 'example.com'localhost' to 'example.org'localhost'
It should show: 'example.com'@'localhost' to 'example.org'@'localhost'

This leads me to believe that a script is not using the correct information.

For now, we've decided not to implement database renames due to the complexity and potential script breakage they can cause.

In that case can you just disable the attempt to rename them so we don’t get messages?

Maybe just a informational message about the database not being renamed?

No rename should be happening though. What's the exact error message that you're getting?