MySQL 8.0 报错:Identifier name 'ix_xxx' is is too long

版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/vkingnew/article/details/83898542
某日在测试库中新加索引报错:
Identifier name 'ix_orgid_warehouseid_businessType_orderCreateTime_state_ordertype' is too long

CREATE INDEX ix_orgid_warehouseid_businessType_orderCreateTime_state_ordertype ON oms_order_2.orders(Org_Id,Warehouse_Id,businessType,orderCreateTime,state,ordertype);

解释信息:
MySQL的索引名支持最大64个字符,超出则报错。

    SELECT CHARACTER_LENGTH('ix_orgid_warehouseid_businessType_orderCreateTime_state_ordertype') AS NUM;

   NUM  
--------
      65


将其中一个s去掉变为64字符则可以执行。
CREATE INDEX ix_orgid_warehouseid_businesType_orderCreateTime_state_ordertype ON oms_order_2.orders(Org_Id,Warehouse_Id,businessType,orderCreateTime,state,ordertype);

注意的地方:
MySQL 虽然支持对象名(table、index、view等)最大为64字符,一般建议不超过32字符。
这样可以方便的兼容其他类型的数据库比如oracle等。

猜你喜欢

转载自blog.csdn.net/vkingnew/article/details/83898542