Вы находитесь на странице: 1из 2

SELECT ... INTO OUTFILE Enter mysql in command-line mode.

C:\MySQL\bin>mysql --user=root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 81 Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> USE community; Database changed mysql> SELECT `Name`, `Address`, `City`, `State`, `Zip`, `Phone` -> FROM `persons` -> WHERE `City` LIKE '%Los Angeles%' -> ORDER BY `Name` ASC, `Zip` ASC -> INTO OUTFILE 'los-angeles-persons.csv' FIELDS ESCAPED BY '""' TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n'; Query OK, 299 rows affected (0.05 sec) mysql> --------------------How to export table data to Microsoft Excel with SELECT INTO OUTFILE statement? I am new to MySQL. I want to export MySQL Table data to Microsoft Excel. Can you explain, how to export data to Microsoft Excel with SELECT INTO OUTFILE? Answer No: 130 MySQL SELECT INTO OUTFILE statement can help you to export MySQL table data to M icrosoft Excel. It s used when anyone wants to direct query output to a file. This file can then be opened by MS Excel, or imported into another database like Mic rosoft Access, Oracle, or any other delimitation supporting software. Take an ex ample, it seems working for me with Windows XP: SELECT * INTO OUTFILE "C:\\export_table_data_excel.xls" FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' FROM database_name.table_name; The export_table_data_excel.xls will be created at C drive. If the target file p ath is omitted, then this file will be created at MySQL data directory. -----------working SELECT * INTO OUTFILE "C:\\19Mar12New1.xls" FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' FROM conntrack.19mar12 limit 1,65535; -------------------How to export table data to text file with SELECT INTO OUTFILE statement? I want to export table data to text file. Is there a way to export results of a query to a file? In other words, if I do a "SELECT * FROM tablename", is there a phrase like "send output to filename.txt", or something? Answer No: 3

To export MySQL table data to text file, MySQL provides SELECT INTO OUTFILE stat ement. It s used when anyone wants to direct query output to a file. You can use t his for your purpose. Take the following example: SELECT * INTO OUTFILE "C:\\export_data_to_txt_file.txt" FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' FROM database_name.table_name; Alternatively, you can run mysql command line client with the 'e' flag and redir ect standard output to a file: mysql> -e 'SELECT * FROM test;' > filename.txt; -------------------------

Вам также может понравиться