运行 SQL 脚本给出语法错误

Running SQL script gives syntax error

我写了一个 sql 脚本,内容如下:

CREATE DATABASE IF NOT EXISTS stock_trading;

USE stock_trading;

CREATE TABLE IF NOT EXISTS transactions(
    user_name VARCHAR(30) NOT NULL,
    passwrd  BINARY(64) NOT NULL,
    balance_cash BIGINT NOT NULL DEFAULT 100000,
    PRIMARY KEY (user_name,passwrd),
)ENGINE=InnoDB;

每次我在 SQL 命令提示符下尝试 运行 它时,它总是给出错误:

ERROR 1064 (42000) at line 5 in file: 'db_script.sql': 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 ')ENGINE=InnoDB' at line 5

脚本似乎是正确的,但我不知道为什么它一直出现此错误。

附加信息:
操作系统Arch Linux
数据库 : MariaDB

您的 table 定义末尾有一个逗号:

PRIMARY KEY (user_name,passwrd),
                              ^^^ remove this

您的完整 table 定义:

CREATE TABLE IF NOT EXISTS transactions(
    user_name VARCHAR(30) NOT NULL,
    passwrd  BINARY(64) NOT NULL,
    balance_cash BIGINT NOT NULL DEFAULT 100000,
    PRIMARY KEY (user_name, passwrd)
) ENGINE=InnoDB;