Search code examples
mariadbinnodb

Err 1064 - You have an error in your SQL syntax; Cannot create table


sql:

CREATE TABLE `forum`
(
  `id` Int UNSIGNED NOT NULL AUTO_INCREMENT,
  `login` Varchar(35) CHARACTER SET utf8mb4 COLLATE utf8mb4_polish_ci NOT NULL,
  `password` Varchar() CHARACTER SET utf8mb4 COLLATE utf8mb4_polish_ci NOT NULL,
  `register` Datetime(0) NOT NULL,
  `last_login` Datetime(0) NOT NULL,
  `birth` Date NOT NULL,
  `about` Varchar(500),
  `sex` Bool,
  `group` Smallint UNSIGNED NOT NULL,
  `rank` Smallint UNSIGNED NOT NULL,
  `avatar` Varbinary(2000) NOT NULL,
  `status` Tinyint UNSIGNED NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`,`group`,`rank`),
  PRIMARY KEY (`id`,`group`,`rank`),
 UNIQUE `id` (`id`)
) ENGINE = InnoDB
 DEFAULT CHARACTER SET utf8mb4
 COLLATE utf8mb4_polish_ci
; 
ALTER TABLE `Forum`.`users` ADD UNIQUE `login` (`login`)
;

Message log:

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TABLE `forum`
(
  `id` Int UNSIGNED NOT NULL AUTO_INCREMENT,
  `log' at line 1
[Err] CREATE TABLE `forum`
(
  `id` Int UNSIGNED NOT NULL AUTO_INCREMENT,
  `login` Varchar(35) CHARACTER SET utf8mb4 COLLATE utf8mb4_polish_ci NOT NULL,
  `password` Varchar() CHARACTER SET utf8mb4 COLLATE utf8mb4_polish_ci NOT NULL,
  `register` Datetime(0) NOT NULL,
  `last_login` Datetime(0) NOT NULL,
  `birth` Date NOT NULL,
  `about` Varchar(500),
  `sex` Bool,
  `group` Smallint UNSIGNED NOT NULL,
  `rank` Smallint UNSIGNED NOT NULL,
  `avatar` Varbinary(2000) NOT NULL,
  `status` Tinyint UNSIGNED NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`,`group`,`rank`),
  PRIMARY KEY (`id`,`group`,`rank`),
 UNIQUE `id` (`id`)
) ENGINE = InnoDB
 DEFAULT CHARACTER SET utf8mb4
 COLLATE utf8mb4_polish_ci
;
[Msg] Finished - Unsuccessfully
--------------------------------------------------

I'm looking at this and looking, seeking for solution on web and can't find what's wrong here.

Just can't execute this sql file, errors. UTF-8 coding.

SQL file dump created with Toad Data Modeler 6.1 Trial


Solution

  • Change:

    ...
    -- `password` Varchar() CHARACTER SET utf8mb4 COLLATE utf8mb4_polish_ci NOT NULL,
    `password` Varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_polish_ci NOT NULL,
    ...
    

    and

    ...
    -- PRIMARY KEY (`id`,`group`,`rank`),
    PRIMARY KEY (`id`,`group`,`rank`),
    ...