I want to add to the defendant. It worked, but it took me about 30 minutes to configure for my needs.
My web server uses centos 6 / cpanel, and the flags and sequence used above did not help me, and I had to reorder and use different flags, etc.
In addition, I used this to dump the file locally, which is not only useful for remote databases, because I had too many problems with selinux and mysql user rights for SELECT INTO OUTFILE commands, etc.
What worked on my Centos + Cpanel server
mysql -B -s -uUSERNAME -pPASSWORD < query.sql > /path/to/myfile.txt
Warnings
No column names
I cannot get the column names at the top. I tried to add a flag:
--column-names
. . .
- .
-D databasename
, , query.sql:
USE database_name;