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 have written a script to extract the contents of a table into a textfile. this is my code

#!/bin/bash

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

1 Answer 1

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

 
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.