MySQL Imports data into Excel

Source: Internet
Author: User

Create a test data table first

CREATE TABLE Users (

Username varchar (+) NOT NULL,

Password varchar (+) not null) Charset=utf8;

Inserting data

Insertinto Users values ("admin", "admin");

Insertinto Users values ("Silence", "Wang Peikun");

Use the following statement to write data from the database to the Test.xls file

Mysql>select Username,password from the users into OutFile "D:\\test.xls";

(Note that MySQL has write permission for the path to the file here.)

( or use the following statement to export to Excel select* into outfile "D:\\test1.xls" from test; )

Because office defaults to gb2312 encoding, and the server may be using UTF-8 encoding, Excel files can be garbled, as follows:


We can re-encode a field as follows:

Mysql>select CONVERT (username using gb2312), convert (password using gb2312) from

Users into OutFile "D:\\test.xls";

This is the normal display in the file:


Mysql> Select CONVERT (username using gb2312), convert (password using gb2312) from

Users into OutFile "D:\\test.xls";

MySQL Imports data into Excel

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.