Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An effective method for exporting query results of mysql to csv

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the effective methods of exporting the query results of mysql to csv, hoping to add and update some knowledge, if you have other questions to understand, you can continue to follow my updated article in the industry information.

To export the query results of mysql to csv, you typically use php connection mysql to execute the query and generate the returned query results using php to generate csv format and then export.

But this is troublesome, and you need to install php on the CVM to achieve this.

Export csv methods directly using mysql

We can use into outfile, fields terminated by, optionally enclosed by, line terminated by statements to implement export csv

The format and function of sentences

Into outfile 'exported directories and filenames'

Specify the exported directory and file name

Fields terminated by 'field delimiter'

Define delimiters between fields

Optionally enclosed by 'field bounding character'

Define the characters that surround the field (numeric field is not valid)

Lines terminated by 'line delimiter'

Define the delimiter for each line

Example: mysql-u rootuse test;select * from table into outfile'/ tmp/table.csv' fields terminated by', 'optionally enclosed by' "'lines terminated by'\ r\ n'

After execution, the recorded data in talbe is exported to the / tmp/table.csv file. Each field is separated by, the field content is surrounded by a string, and each record is wrapped with\ r\ nnewline.

This article explains the method of exporting query results to csv through mysql. Please follow us for more information.

Related recommendations:

Performance comparison between php array_push and $arr [] = $value

How to use php to set up a session that strictly controls the expiration time

How to use php to judge whether memcache key/value exists or not

These are the details of the effective methods for exporting mysql query results to csv. Please pay attention to other related articles for more information.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report