Migrating a MySQL database containing views

You may have come across this problem: say you have a MySQL database called ‘myblog’ which you’re moving to a new server on a different provider, and said provider doesn’t allow you to name the database, but instead use their own scheme, ‘user82_db1’ for example.

If you happen to have views in your database, this will cause the import to fail, as those views would still refer to ‘myblog’ instead of the new database. Fortunately, this is easily fixed using the ‘rpl’ command. Say your database is backed up as ‘myblog-backup.sql’:

# rpl "\'myblog\'." "\'user82_db1\'." myblog-backup.sql

This will replace any instance to ‘myblog.’ with ‘user82_db1.’ and allow you to import a working database.