mysql export data to excel

method one

PHP tutorial uses mysql commands and shell

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

 

Method 2 Open bestlovesky.xls in text mode, then save as, select ansi encoding in encoding, save

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


Method three

cd D:\wamp\bin\mysql\mysql5.6.17\bin

mysql your_database  -uroot  -p  -e  "select   *   from   test.table2 "   >   /home/test.xls

Use the sz command to download the file to the local, open if the Chinese is garbled,

Because the default encoding of office is gb2312, the server-side generation is likely to be utf-8 encoding. At this time, you have two choices: 1. Use iconv on the server side for encoding conversion

iconv -futf8 -tgb2312 -otest2.xls test.xls
If the conversion goes well, download it from the server and you can use it.
If the conversion does not go well, it will prompt: iconv: illegal input sequence at position 1841 Similar to this error,
download test.xls first. At this time, the file is utf-8 encoded and opened with excel, with garbled characters.
Open test.xls as text, then save as, select ANSI encoding in encoding, and save.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326992119&siteId=291194637