Bug #35634 | 'mysql' client: 'source' should stop after first failed command | ||
---|---|---|---|
Submitted: | 28 Mar 2008 8:54 | Modified: | 1 Oct 2008 15:08 |
Reporter: | Guilhem Bichot | Email Updates: | |
Status: | Won't fix | Impact on me: | |
Category: | MySQL Server: Command-line Clients | Severity: | S4 (Feature request) |
Version: | 5.1-bk | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[28 Mar 2008 8:54]
Guilhem Bichot
[28 Mar 2008 9:14]
Jon Stephens
Why don't we want to offer users a choice in the matter?
[31 Mar 2008 9:17]
Guilhem Bichot
Clarification from Jon: he meant that there are cases where an error in the execution of the script is not a real issue (for example if the script is just a bunch of INSERTs to produce an arbitrary data load), and where it would be annoying if the entire script aborted at first error. He suggests that the behaviour to stop at first error become default but with a command-line option to revert to the no-stop behaviour (Jon suggests the option could allow the user to choose what class of statements should not cause a stop: INSERT, UPDATE, DELETE... - though Guilhem thinks this is then a separate feature request as the one here).
[31 Mar 2008 18:00]
Valeriy Kravchuk
Thank you for a reasonable feature request.
[9 Jul 2008 20:50]
Guilhem Bichot
In mysql-maria now, in 6.0-maria in a few days, and later in 6.0-main, there is 'mysql --abort-source-on-error' which very probably is what was requested (to be tested). Monty implemented it.
[1 Oct 2008 15:08]
Konstantin Osipov
If you would like MySQL command line client to stop after the first failure, please use \e and \run instead of source.
[1 Oct 2008 19:53]
Guilhem Bichot
Expanding on Konstantin's advice: one can do: \e (this creates a tmp file and opens it with $EDITOR) then import your SQL script into the tmp file in the editor (:r in vi, insert-file in Emacs, copy-paste, etc) then exit your editor: \e automatically loads the content of this temporary file in memory ready to execute, you just need to type ";" or \go to execute it.
[14 Jun 2011 9:50]
Steven Hartland
The \e option doesn't seem to be a very practical example when the source file is large e.g. when restoring a backup which can be many many GB's Adding an abort on error option would be much more preferable.
[17 Mar 2012 2:25]
Peter Soltesz
I found a temporary workaround for this problem. First open a connection with --skip-reconnect Second after the query, which on generating an error should stop execution insert the query: kill connection if(@@error_count>0,connection_id(),0); or equivalent: kill if(@@error_count>0,connection_id(),0); Hopefully thread id 0 cannot exist... (can it?) this will generate an error which is not so nice, but will exit on the preceeding query's error... downside: it cannot be run in other forms than source otherwise it will exit after the first test.