Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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 mysql-import.sh and put following contents in it.

#!/bin/bash

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

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

EOF

Then chmod +x mysql-import.sh and run the script as,

./mysql-import.sh > /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

 
discard

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.