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 am using Ubuntu 13.04 and installed MySQL Server version: 5.5 .

All I want simply , if I doing a MySQL query then its output should have to store in a text file. How can I achieve this ?

for example :

select * from raja

then output of table raja should have to store in a text file along with terminal display.

Thank you.

share|improve this question
up vote 1 down vote accepted

Like this:

mysql -u username -p -e 'select * from raja;' database_name >> file_name.txt

If you want to append use >> otherwise >.

share|improve this answer

mysql -u*user* -p*passowrd* -e 'SQL Query' database > filetosave

-u : Specify mysql database user name
-p : Prompt for password
-e : Execute sql query
database : Specify database name

So for your case:

    mysql -u raja -p -e 'select * from raja' rajadb > results
share|improve this answer
He posted before you did , and Its worked. So I am accepting his answer. Both are great answers.Thank you.:) – Raja Sep 9 '13 at 12:47

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.