Mon, 14 Jan 2008

ERROR 1005 (HY000): Can't create table './Database/Table.frm' (errno: 150)

If you're trying to import a dump file created using mysqldump and you get an error like:

ERROR 1005 (HY000): Can't create table './Database/Table.frm' (errno: 150)

Then you've just been bitten by mysqldump being far too stupid. The problem occurs because mysqldump includes foreign key constraints in the initial CREATE TABLE command, so if a table refers to a table that doesn't currently exist, it throws an error. mysqldump does correctly disable the contraints when inserting data into the tables. The correct way for this would be for mysqldump to create all the tables without the constraints, use ALTER TABLE to add the constraints to the tables, and then importing the data into the tables.

The workaround for this problem is to use:

SET FOREIGN_KEY_CHECKS = 0;
source dump.sql
SET FOREIGN_KEY_CHECKS = 1;

Update: Someone has pointed out that it appears that mysql 5 has fixed this problem by including the above statements in the dump.

[database,MySQL,gotchas] | # Read Comments (1) |

Comments

Please help me

mysql> alter table cuti add jumlahcuti char(2);
ERROR 1005 (HY000): Can't create table '#sql-766_cb0' (errno: 13)
Posted by Mr. M at Wed Oct 8 04:47:06 2008

Name:


E-mail:


URL:


Comment:


Please enter "fudge" to prove you are a human