Output MySQL source results to log file
Asked Answered
B

3

32

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.

Batiste answered 10/11, 2010 at 16:9 Comment(1)
Have you checked the pager command?Protoplast
B
51

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'

Bangui answered 9/5, 2011 at 20:5 Comment(2)
Also, if you want to stop the output, just type notee (source)Derrek
I'd also jout like to highlight that you can use any text format for this e.g. session.log etc.Kirk
H
4

You could do it from the shell prompt:

$ mysql -p dbname < foo.sql > foo.txt
House answered 10/11, 2010 at 16:15 Comment(0)
G
2

Use the command line:

mysql -p dbname < ~/foo.sql > ~/foo.txt
Gibran answered 10/11, 2010 at 16:15 Comment(2)
Did the database load as you wanted it to though? Only error messages will be added to the file. Oh, it will also stop on the first error, unless you give it a command line option to keep going past errors.Gibran
It completed without error at first. I then tried it again and set my max_allowed_packet to 5M so it would intentionally error. It did get an error but foo.txt did not list this error.Batiste

© 2022 - 2024 — McMap. All rights reserved.