DISQUS

Tech-Recipes: Save MySQL query results into a text or CSV file | MySQL | Tech-Recipes

  • Mike · 9 months ago
    Thanks for this, a MySQL noob like myself always forgets the exact syntax!

    Bookmarked.
  • sshah · 9 months ago
    Thanks for the helpful post but my problem is that when i execute the query and go to the location where i saved the file, i can't find any file there. However if i again try the same command it says "File already exists" but actually there is not. Wha'ts wrong?
  • Amit · 7 months ago
    I am facing the same problem. Did you find the answer?
  • Heini · 7 months ago
    Just like this:

    SELECT order_id,product_name,qty
    FROM orders
    INTO OUTFILE 'c:/tmp/orders.csv'

    Just type in the drive you want.
  • Udit Chaudhary · 5 months ago
    This happens only if you have executed the query twice and redirecting it to same location with same name otherwise rest is fine.
  • Sven · 4 months ago
    I got the same problem when I connect to a remote database server. The file is created on the remote server.

    Anyone know how to get this file created on the local host?
  • Sumesh · 7 months ago
    Is there a similar thing available in oracle?
  • Leion · 7 months ago
    How can I used a a date value in the output file?
  • jai · 5 months ago
    I dont know y the new line operator is not at all working in my MySql...
    am using version 5.0...


    could some one plz help me out................
  • shiv` · 4 months ago
    can u tell me how can i get the column names along wtiht the result set
  • danishm · 4 months ago
    For oracle ,you can use toad
  • palcb · 4 months ago
    "Thanks for this, a MySQL noob like myself always forgets the exact syntax!

    Bookmarked."

    it was those people who memorized syntax or function than understanding what a language can do or cant do was noob.
  • augusto · 1 month ago
    how a very few lines may save lots of time.....
    thanks a lot!
  • regbailey · 1 month ago
    Thank you very much indeed. Your article has just saved me a tremdous amount of time, trouble & effort. An excellent example of the web being used as it should be.

    Many thanks again.

    Reg Bailey.
  • regbailey · 1 month ago
    Hi,

    Also discovered that including the 'optionally' keyword, eg:

    ... optionally enclosed by '"' ...

    that MySQL will decide which fields (eg. text, char etc) need enclosing in double quotes and which fields (eg. int, float etc) do not in order to comply with strict CSV format. Depending on your table make-up & size, this too is a great time saver. Mant thanks again for pointing me (and many others) in the right direction.

    Reg.
  • aaruthra · 2 weeks ago
    it was very useful buddy..but i need how to save the commands given by me... :)