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.

2 thoughts on “ERROR 1005 (HY000): Can’t create table ‘./Database/Table.frm’ (errno: 150)

  1. Please help me

    mysql> alter table cuti add jumlahcuti char(2);
    ERROR 1005 (HY000): Can’t create table ‘#sql-766_cb0’ (errno: 13)

  2. skelly
    on said:

    This problem also comes from write permission failure on the data directory. For example when I did an `ls -l mysql/var` it showed by db dir as:

    username : username mydatabase

    A quick `chown -R mysql:mysql mysql/var/mydatabase` made the error go away. Funny how cryptic mysql can be about relatively simple error conditions. Mine was the result of a binary backup/restore of some data, and the restore process did not retain the owner information.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.