Applicable to:
- Plesk for Linux
Symptoms
When restoring a database from a dump / backup, the operation fails with one of the following error messages:
# mysql -uadmin -p`cat /etc/psa/.psa.shadow` database < database.sql
ERROR 1005 (HY000) at line 15: Can't create table `database`.`table` (errno: 150 "Foreign key constraint is incorrectly formed")
# zcat mysql.daily.dump.0.gz | sed -n '/-- Current Database: `roundcubemail`/,/-- Current Database:*/p' | MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -uadmin --default-character-set=utf8
ERROR 1215 (HY000) at line 15: Cannot add foreign key constraint
Cause
Unclear.
Resolution
Solution I
- Connect to your server via SSH.
-
Restore the database with
SET SESSION FOREIGN_KEY_CHECKS=0;key:# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql --init-command="SET SESSION FOREIGN_KEY_CHECKS=0;" -uadmin database < database.sql
For example, to restore the
roundcubemaildatabase from the latest Plesk daily dump, run the command:# zcat mysql.daily.dump.0.gz | sed -n '/-- Current Database: `roundcubemail`/,/-- Current Database:*/p' | MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -uadmin --init-command="SET SESSION FOREIGN_KEY_CHECKS=0;"
Comments
Please sign in to leave a comment.