Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to log the error and warning while restoring the sql dump on MySql ? Following are the steps we are doing.

mysql> CREATE DATABASE dbname;

mysql> USE dbname;

mysql> SOURCE dbdumpname.sql

share|improve this question
up vote 0 down vote accepted

Restore it from bash not from mysql shell.

mysql -u root -p db_name < dumpfilename.sql > /var/tmp/mysqldump.log 2>&1

Create a shell script named and put following contents in it.


mysql -u root -p'password' -h hostname db_name << EOF

USE dbname;
SET foreign_key_checks=0;
SOURCE dbdumpname.sql;


Then chmod +x and run the script as,

./ > /var/log/mysqldump.log 2>&1

share|improve this answer
Ok How can I set the foreignkey_checks=0 with the restore command. – Aha Dec 2 '11 at 9:47
@Arun I am not getting your question. – Sachin Divekar Dec 2 '11 at 10:12
While restoring the dump there are possibility of exception due to foreignkey_checks. So we are doing the same as follows.mysql> CREATE DATABASE dbname; mysql> USE dbname; mysql > set foreign_key_checks=0; mysql> SOURCE dbdumpname.sql; How can I do this with mysql -u root -p db_name < dumpfilename.sql > /var/tmp/mysqldump.log 2>&1 – Aha Dec 5 '11 at 5:05
@Arun I have updated the answer. Check if it is working. – Sachin Divekar Dec 5 '11 at 6:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.