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 );