Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save MySQL query results into a text file

Tags:

mysql

I want to save a MySQL query result to to a text file like this:

SELECT * FROM orders INTO OUTFILE '/data.txt'

However, I don't have write permission on the server. Where can I write to or is there a simpler way?

like image 801
melodrama Avatar asked Oct 09 '13 22:10

melodrama


2 Answers

use this command:

mysql -uroot -p -e "select * from database_name.table_name" > filename.txt

Enter the password and all is done

like image 163
Mukul Aggarwal Avatar answered Nov 04 '22 00:11

Mukul Aggarwal


select * into outfile  'sd1.txt' from orders;

or

select * into outfile  'sd1.sql' from orders;
like image 6
Hrithu Avatar answered Nov 03 '22 23:11

Hrithu