Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm on a local windows machine. The MySQL DB is on a CentOS machine elsewhere on the same local network. I want to output the results of the query that I'm typing directly into Putty into an Excel (or csv) file elsewhere on the local network. How would I do this?

I tried something like

mysql> select * from table > \\server\my_documents\output.csv

but no luck.

share|improve this question

1 Answer 1

Looks like you're starting a mysql interactive session. Instead, you'll want to execute the SQL from a text file, i.e.

mysql database_name < input.script.sql > output.file

You'll want to ensure that your SELECT statement outputs something usable, so something like what's mentioned in this answer on stackoverflow. Note that that answer already has the outfile specified, so you wouldn't need the redirect as shown above . . .

SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.