Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » MySQL

Convert MySQL table to CSV file

Submitted by on March 27, 2008 – 4:41 pm 6 Comments

CSV is a field-separated format that can be easily imported into a spreadsheet application. Usually the separator field is a comma. However, sometimes it is easier to select a more unusual character (like “@” for example), so that the field separator is not confused with commas in the field values.

In the example below we will dump contents of table1 in database1 to /tmp/database1_table1.csv. On the command line type this:

mysql -udbuser -pdbpasswd << EOF
SELECT * INTO OUTFILE '/tmp/database1_table1.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY 'n' FROM database1.table1;
EOF

Print Friendly, PDF & Email

6 Comments »

  • airdogspace2 says:

    i have a data base in csv formate , i will like to know how to use it in php mysql . i am building a website for a school and they have the grades in csv format and the site i am building is in php mysql . i will like to know how to convert the csv format to a formate that can be used in mysql

  • Dark_LovexXx says:

    i need a script to run in php, so when i run it, it takes the info and gives me the option to save it as a csv file.

    any idea?

  • Sir fliesalot says:

    or do i need to set up a page to receive it….halp! and can the stuff attached to it come too

  • Xedo says:

    I have multiple .csv files with raw data in them. I need to summarize them and bring them all together into a readable, “pretty,” output. This data comes monthly right now, but in the same format. So is there a scripting language I can learn to do this? Where should I start?

  • everythingisgonnabefine says:

    So, I’m looking for a way for my php page with a html table + data from mysql db and converting the html table and its data to a .doc so that after it has been downloaded and can be opened and printed in MS word.

    thanks for those who will reply

  • sakyue1993 says:

    I have a LINUX web server, which supports SQL database only. How can I convert my Access database into SQL?

Leave a Reply to sakyue1993 Cancel reply

%d bloggers like this: