AktifPerunding

  • Home
  • About
  • Our Team
  • Portfolio
  • News
  • Contact

categories

  • Civil & Structure
  • Electrical
  • Electronic
  • Information & Technology
  • Mechanical
  • Photovoltaic
  • PHP
  • Programming
  • Solar Power
  • Technology

Dumping and importing from/to MySQL in an UTF-8 safe way

In a nutshell: to avoid your shell character set from messing with imports, use -r to export and SOURCE when importing.

Admin APSB 26/08/2019 Information & Technology, Programming

Dumping safely

# Do not do this, since it might screw up encoding mysqldump -uroot -p database > utf8.dump # this is bad

Better do:

mysqldump -uroot -p database -r utf8.dump

Note that when your MySQL server is not set to UTF-8 you need to do mysqldump --default-character-set=latin1 (!) to get a correctly encoded dump. In that case you will also need to remove the SET NAMES='latin1' comment at the top of the dump, so the target machine won't change its UTF-8 charset when sourcing.

If you only want to dump the structure without data, use

mysqldump -uroot -p --no-data database -r utf8.dump

Importing a dump safely

# Do not do this, since it might screw up encoding mysql -u username -p database < dump_file # this is bad

Better do:

mysql -uroot -p --default-character-set=utf8 database mysql> SET names 'utf8' mysql> SOURCE utf8.dump

AktifPerunding

DISCLAIMER: We are not responsible for any lost or corrupt personal data information when using this website

information

CONSULT . DESIGN . BUILD

Tel: +603 8959 3901

Email: [email protected]

Working Hours: 9AM-5PM (+8 GMT)

Instagram

© Copyright Aktif Perunding Sdn. Bhd. All Rights Reserved

Powered by Maximum Builders