MySQL: run sql script file in command line and get the erros in a log file

Posted on 2009-04-29
Last Modified: 2012-05-06
When you run a sql script file in command line with MySQL you can redirect the output of the query in a file but not the errors apparently:

>mysql -uuser -ppassword < sql_script_file > output_file

If the sql_script_file returns a result like table rows they will get into the output_file but if there is an error within the script it is not redirected to the outpyt_file but only to the console.

How can I get the errors from a script file to be saved to a output_file with MySQL.
Question by:Zberteoc
    LVL 25

    Expert Comment

    Have you tried using the --tee switch to output everything to an output file..

    See complete command line reference below -
    LVL 21

    Accepted Solution

    Try this:
    mysql -uuser -ppassword < sql_script_file  1> output_file.log 2>output_file.err
    LVL 26

    Author Closing Comment

    Thanks, that was it!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi ( had suggested a “sed” way, I actually shell …
    I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now