DO YOU NEED A CONTENT WRITER FOR YOUR BUSINESS?

Your One-Stop Solution for All Content Needs! Click here for more!
MySQL

MySQL export table to CSV

Share

MySQL provides an easy way to export table result set into a CSV file.

Suppose we have a query like:

SELECT name, email, age
FROM
users
WHERE status = 'Active';

So if we need to export this data into a csv file then using below query we can do:

SELECT name, email, age
FROM
users
WHERE status = 'Active'
INTO OUTFILE 'C:/xampp/users.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
LINES TERMINATED BY '\r\n';

To add a column heading you need to UNION as below:

(SELECT 'Name','Email','Age')
UNION
(
SELECT name, email, age
FROM
users
WHERE status = 'Active'
INTO OUTFILE 'C:/xampp/users.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
LINES TERMINATED BY '\r\n';
);
Namaste UI (Author)

Namaste UI collaborates closely with clients to develop tailored guest posting strategies that align with their unique goals and target audiences. Their commitment to delivering high-quality, niche-specific content ensures that each guest post not only meets but exceeds the expectations of both clients and the hosting platforms. Connect with us on social media for the latest updates on guest posting trends, outreach strategies, and digital marketing tips. For any types of guest posting services, contact us on info[at]namasteui.com.

Recent Posts

What Should You Do When a Dog Bites You?

Not every dog is friendly, and even friendly dogs can attack when threatened or provoked.…

3 hours ago

Holding Manufacturers Accountable: Steps to File a Lawsuit for Pressure Cooker Explosions

Pressure cookers have become a favored kitchen appliance because they can quickly and efficiently cook…

1 day ago

Reasons to Hire a Shopify Web Designer for Your Business

Shopify has quickly become the preferred platform for businesses seeking to build an online presence.…

4 days ago

How To Gain Free Instagram Followers and Likes Easily-GetInsta

We all know that Instagram is a very famous social platform that attracts more and…

7 days ago

How to tell whether high-level glass is toughened or laminated

Glass at height is easy to overlook, in both senses. It is out of reach,…

2 weeks ago

Signs Your Rental Business Has Outgrown Spreadsheets (and What to Do Next)

Almost every rental business starts the same way. A handful of items, a notebook or…

2 weeks ago