3

Is there an easy way to run a MySQL query from the PowerShell command line and output the results into a csv formatted file?

This question is the same as How to output MySQL query results in CSV format? except in Windows. I had to figure it out in PowerShell but my answer didn't belong on the linux question. So here's the Windows+PowerShell sibling.

1 Answer 1

2

Stan's answer from How to output MySQL query results in CSV format?, adapted for Windows PowerShell

mysql my_database_name -u root | Out-File .\my_output_file.csv

This gives me a mysql prompt, but without the usual mysql > at the start. I type:

source C:\Aboslute\Path\With Spac es\Without\Quotes\To\my_select_statement.sql

It gives an error message and exits if there is a problem with the command, or gives me the empty prompt if the command executed successfully. I type exit to finish up.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.