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.
1 Answer
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'