How to import an excel file from mysql

Source: Internet
Author: User
Tags mysql tutorial php mysql

How to import an excel file from a mysql tutorial

The simplest method is to use the php tutorial myadmin to directly import the xls file. This is not much to mention. Let's take a look at the following two methods to combine the php mysql command with the shell.


Method 1:

 

Select * into outfile './zhutiai.xls' from zhutiai where 1 order by id desc limit 0, 50;
 


Method 2:

 

Echo "select id, name from zhutiai where 1 order by id desc limit 0, 50; "|/usr/local/mysql/bin/mysql-h127.0.0.1-uroot-p123456>/data/zhutiai.xls
 


Because the default office Code is gb2312, the server generates UTF-8 encoding, which may cause Chinese characters to be exported to garbled characters. The solution is as follows:

Method 1. Use iconv on the server side for encoding conversion

 

Iconv-futf8-tgb2312 -ozhutiai2.xls zhutiai.xls
 


4.1.2.open zhutiai.xls in text format, save it as, select ansi encoding in encoding, and save

If method 1 fails to be converted, the following error occurs: iconv: illegal input sequence at position 1841,
Download zhutiai.xls first. The file is UTF-8 encoded and opened in excel with garbled characters.
Open zhutiai.xls in text format, save it as, select ansi encoding in encoding, and save

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.