Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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.:) –  AgentCool Sep 9 '13 at 12:47
add comment

Your Answer

 
discard

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.