mysql provides an easy mechanism for writing the results of a select statement into a text file on the server. using extended options of theinto outfilenomenclature, it is possible to create a comma separated value (csv) which can be imported into a spreadsheet application such as openoffice or excel or any other applciation which accepts data in csv format.
In your terminal
Given a query such ass
SELECT * FROM pet;
which returns all columns of data, the results can be placed into the file /tmp/pet.txt using the query:
SELECT * FROM pet
INTO OUTFILE ‘/tmp/pet.txt’
This will create a tab-separated file, each row on its own line. To alter this behavior, it is possible to add modifiers to the query:
SELECT * FROM pet
INTO OUTFILE ‘/tmp/pet.csv’
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘/n’
In this example,the fields will be separated by commas, and each row will be output on a new line separated by a newline (/n). Sample output of this command would look like:
Fluffy,Harold,cat,f,1993-02-04,0000-00-00
Claws,Gwen,cat,m,1994-03-17,0000-00-00
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号