Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:53:32+00:00 2026-05-28T16:53:32+00:00

i need to export data from a table to a csv. i have the

  • 0

i need to export data from a table to a csv. i have the following structure (not really my table but for demo purposes)

CREATE TABLE `mytable` (
  `id` int(11) DEFAULT NULL,
  `mycolumn` varchar(25) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 

with data (about 3000 records). now i want to export some of these records (from a script i run via cronjob)

SELECT * INTO OUTFILE '/tmp/mytable.sql'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM mytable;

it shows:

Query OK, 3 rows affected (0.00 sec)

then i do:

ls: cannot access /tmp/mytable.sql: No such file or directory

where is my file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:53:33+00:00Added an answer on May 28, 2026 at 4:53 pm

    When you use the INTO OUTFILE command, it export the data to the local folder of the server not the one you are executing the query.

    Example: you are on your computer (ip: 192.168.0.100) and you connect to the mysqlserver (ip: 192.168.0.101) using the mysql command: mysql -uuser -h192.168.0.101 -A database. By executing the SELECT * INTO OUTFILE the file is saved on the mysqlserver (ip: 192.168.0.101) and NOT on your computer (ip: 192.168.0.100).

    Now, you can use a script that creates a CSV file (in your cronjob – you select all the data, generate the file and send via scp to the other server).

    Or – You can also have a NFS mounted on /shared/ and when you create the file automatically the other server has it.

    Or – you can simply run a mysql command in a bash script like this from your first server.

    mysql -uroot test -B -e "select * from test.mytable;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > /tmp/filename.csv
    

    source: http://tlug.dnho.net/node/209

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to export data from a table in database A, then import it
I need to export data from an existing TABLE. Till recently I used -
I am trying to create a CSV file from a dynamically generated table.I have
I need to export data to a file from a huge table with only
I want to export data from a table to a specifically formatted XML file.
Is there any data export framework in .net or something. I have need to
I need to export a table from phpmyadmin to a comma delimited text file.
Is there an iSeries command to export the data in a table to CSV
Can i export a data from a table to an excel sheet, using javascript?
I have a query that selects 3 columns from a SQL table, I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.