How to export xls and csv data from mysql with garbled characters

Source: Internet
Author: User
Tags mysql tutorial mysql command line

How to export xls and csv data and garbled data in the mysql tutorial
The following information about
First, let's take a look at the method for exporting and importing xls and csv data from mysql, and the effective solution when the import is garbled,

Run the following SQL statement on the mysql command line:

Mysql> select * from xi_table into outfile 'd: www.bKjia.c0mtest.xls ';

Sometimes garbled characters appear when an excel file is opened,
Because the default office Code is gb2312, the server generates UTF-8 encoding. iconv can be used on the server for encoding conversion: iconv-futf8-tgb2312 -otest2.xls test.xls

If you do not have the Server Management permission, you can use the following method to solve the Garbled text problem:

Download test.xls first. At this time, the file is UTF-8 encoded and opened in excel with garbled characters.
Open test.xls in text format, save it as, select ansi encoding in encoding, and save.
In this way, you can use excel to solve the garbled problem.


The target directory for exporting csv files from mysql must be a directory with mysql write permission.

Export

Select field1, field2, field3 from tablename into outfile '/home/output1.csv 'fields terminated by', 'optionally enclosed by ''lines terminated by 'n ';

Import

Load data local infile '/home/output1.csv' into table tablename fields terminated by ', 'Lines terminated by 'n' (field1, field2, field3 );

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.