Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have written a script to extract the contents of a table into a textfile. this is my code


mysql -uroot -ppasswd database select * from table>textfile.txt

i have changed permissions on the file and when i run it using ./myscript it creates textfile.txt but loads into it the mysql manual.How can i achieve my desired result

share|improve this question
up vote 4 down vote accepted

It shows you the manual because it's the wrong syntax. Try this:

mysql -uroot -ppasswd database -e "select * from table" >textfile.txt

From the manual:

-e, --execute=name  Execute command and quit. (Disables --force and history file.)
share|improve this answer

Your Answer


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.