Garbled characters for Database Backup Using mysqldump

Source: Internet
Author: User

The garbled problem of using mysqldump to back up the database recently in the project, because the system needs to provide the database backup function, after some searches on the Internet, I think the simple mysqldump (1) java code [java] <span style = "font-size: 14px; "> String backupSQL =" cmd/c mysqldump-urootdd -- extended-insert = false-hlocalhost fts> "+ DB_BACKUPFILE_PATH +" "; Runtime runtime = Runtime. getRuntime (); System.out.println(runtime.exe c (backupSQL); </span> by executing the above code snippet, Chinese characters are garbled, at first, it was suspected that the database encoding was related, so we used the following method to query the database encoding (2)> show variables like 'character % ';

After the above steps, we can confirm that the encoding of the database is correct. After another online search, we can find the following conclusion: "If the character set on the MySQL server is latin1 or another one, Chinese characters from mysqldump are garbled! A simple method is to add the default character set options, such as mysqldump [-h 127.0.0.1-P 3307]-u username -- default-character-set = gbk-p databasename> dumpfile.txt, -- When the default-character-set knows that the data content is Chinese, it can be specified as gbk, so that even if the database itself sets the character set to the Chinese language of the file latin1, it can be normal! ", Finally, change the code to the following form (3) Final java code [java] <span style =" font-size: 14px; "> String backupSQL =" cmd/c mysqldump-urootdd -- default-character-set = gbk -- opt -- extended-insert = false-hlocalhost fts> "+ DB_BACKUPFILE_PATH + ""; runtime runtime = Runtime. getRuntime (); System.out.println(runtime.exe c (backupSQL); </span> after the preceding modification, the exported file's Chinese characters are displayed normally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.