【问题标题】:Error while executing MySQL queries on MySQL server version 8在 MySQL 服务器版本 8 上执行 MySQL 查询时出错
【发布时间】:2019-07-18 12:56:09
【问题描述】:

我正在尝试在 MySQL 服务器上执行查询,但它抛出了错误。它在 MySQL 服务器 5.1 上运行良好,但现在我使用的是 8.0

查询

SELECT group1s.group_id, group1s.customer_id
 FROM icm_b_instance_group1s as group1s inner join icm_b_instance_groups 
as groups on group1s.group_id = groups.group_id
 where group1s.is_active = 'Y' and groups.is_active = 'Y';

[代码:1064,SQL 状态:42000] 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册 在 group1s.group_id = 上的 'groups 附近使用正确的语法 第 2 行的 groups.group_id'

【问题讨论】:

    标签: mysql mysql-8.0


    【解决方案1】:

    来自MySQL 8.0 Keywords and Reserved Words

    组(R); 8.0.2中添加(保留)

    所以您用作别名的groups 是保留字,不能在版本 8.0.2+ 中使用

    【讨论】:

    • 它可以使用,如果你在它周围使用反引号。虽然最好将别名重命名为其他名称。
    • 在任何情况下都不应使用保留字以避免此类错误和混淆。问题在于每个新版本可能添加的新保留字。所以重命名所有旧用途是最好的选择。
    • 非常感谢@forpas
    猜你喜欢
    • 2011-09-01
    • 2012-11-04
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多