Search code examples
mysqlcreate-table

MYSQL Table Error - 1064


Trying to create the following table:

CREATE TABLE login (
        IdUser int(11) NOT NULL AUTO_INCREMENT,
        username varchar(45) CHARACTER SET latin1 NOT NULL,
        pass varchar(45) CHARACTER SET latin1 NOT NULL,
        PRIMARY KEY (IdUser),
        ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$);

Doesn't seem to work properly. The error I'm getting in MYSQL is:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$' at line 6


Solution

  • Bracket in the wrong spot:

    PRIMARY KEY (IdUser),
    ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$);
                                                         ^----
    

    should be

    PRIMARY KEY (IdUser)   <--note removed comma
    ) ENGINE=MyIsam etc...
    ^---
    

    You're treating those table options as they were fields, by placing them WITHIN the () field definition block.