Converting mysql databases to UTF8

UTF8 is the way to go when you're creating a new database for an application, but how do you get your existing applications upgraded? We dump the database and then import it with the new character set so we can test things out:
# Export your latin1 encoded database

        mysqldump
            --user=username
            --password=password
            --default-character-set=latin1
            --compatible=mysql40 dbname
            > dump.sql
        
        # Import database as utf8

        mysql
            --user=username
            --password=password
            --default-character-set=utf8
            dbname
            < dump.sql
Note: wrapped for your reading convenience; these should all be on one line if you're typing them at the command line.

Established 2005 · Databasically © 2016