简体   繁体   中英

How to log sql errors when restoring database from dump file

Pre-apologies for any duplication here but I swear I have researched (and learned a lot in the process).

Environment is MySQL 5.5 using MYISAM table engine on Windows 7.

The job is to restore a database dumped from MySQL 4.0. I do this from the command line (I tried using Oracle's MySQL Workbench import utility but it would fail if it encountered an error). The restoration completes but I know there are errors getting thrown. I want to capture those so I can make sure the restoration completes without error.

General_log doesn't seem to capture anything (and yes - it's turned on). The other log file (local_host_name.log) doesn't seem to capture sql statement level errors at all.

Is there a method for capturing errors when restoring from the command line? Is there a way to perhaps edit the dump file itself with throw/catch statements that would write errors to a log file?

Thanks in advance -- I'm a MS SQL guy who is brand new to MySQL.

@Rob in your prompt (cmd?) try something like:

mysql -u your_user your_database <c:\path\to\your_script.sql >stdout_output.txt 2>stderr_output.txt

there isn't angle brackets, the symbols '<' and '>' are redirect signals of command line shell.

我使用bash脚本来恢复MySQL TB数据库并将输出记录到一个文件,如下所示,

/bin/bash /home/installation/scripts/finqa_restore.sh 2>&1 | tee /home/installation/scripts/output-stat.txt

This worked for me:

 pv import_test.sql | mysql -urootuser -pyourpassword the_db_name >st_out_log.txt 2>error_log.txt

One issue I had is that it only seems to capture one error. Perhaps the script stopped executing after the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM