mysql query result to file

Shell
mysql -user -pass -e "select cols from table where cols not null" > /tmp/output
Source

Also in Shell: