Guest User

Untitled

a guest
Apr 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. # Dump the old database as latin1, because ironically, mysqldump defaults to utf8.
  2. mysqldump --default-character-set=latin1 db > db.dump
  3.  
  4. # If you need to convert a MySQL dump from one character set to another, use iconv.
  5. iconv -f LATIN1 -t UTF-8 < db.dump > db.dump
  6.  
  7. # If you've been running mysqldump without parameters on a latin1 instance, you can convert the dump from UTF8 to latin1 to correct it.
  8. iconv -f UTF-8 -t LATIN1 < db.dump > db.dump
  9.  
  10. # Rewrite the dump to say 'utf8' and 'utf8_unicode_ci' in all the right places.
  11. sed -e 's/SET NAMES latin1/SET NAMES utf8/g' -i db.dump
  12. sed -e 's/CHARSET=latin1/CHARSET=utf8 COLLATE=utf8_unicode_ci/g' -i db.dump
  13.  
  14. # Create a new database with the correct parameters.
  15. create database db character set utf8 collate utf8_unicode_ci;
  16. # Verify it.
  17. show create database db;
  18.  
  19. # Pipe the converted database dump into MySQL.
  20. mysql -h hostname --default-character-set=utf8 -u root -p db < db.dump
Add Comment
Please, Sign In to add comment