Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output MySQL source results to log file

I am trying to execute foo.sql using the source command in MySQL.

When I type the command, the file is sourced accordingly:

mysql> source ~/foo.sql 

Now, there are a lot of statements being executed in this file and I would like to review the success/failure of these statements. Is there a way I can pipe the results of the statements to a log file, foo.txt?

I am thinking something along the lines of:

mysql> source ~/foo.sql into outfile ~/foo.txt 

However, typing this command appears to assume that everything following the source statement is one file name; so it is trying to source a file named '~/foo.sql into outfile ~/foo.txt', which obviously doesn't exist.

like image 339
Isaac Avatar asked Nov 10 '10 16:11

Isaac


People also ask

How do I redirect output to a file in MySQL?

Save MySQL Results to a File There's a built-in MySQL output to file feature as part of the SELECT statement. We simply add the words INTO OUTFILE, followed by a filename, to the end of the SELECT statement. For example: SELECT id, first_name, last_name FROM customer INTO OUTFILE '/temp/myoutput.

How do I get output in MySQL?

The Output is located at the bottom of MySQL Workbench. Its select box includes the Action Output , History Output , and Text Output options.

How do I store the MySQL query results in a local csv file?

use the command insert...select to create a "result" table. The ideal scenario whould be to automatically create the fields of this result table, but this is not possible in mysql. create an ODBC connection to the database. use access or excel to extract the data and then save or process in the way you want.


1 Answers

From within your MySQL client, type

tee session.out 

From that point on, all the I/O of in your current client session is written to the file 'session.out'

like image 66
Vlad the Impaler Avatar answered Sep 29 '22 15:09

Vlad the Impaler