Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-30 · container image mysql:8.4
MySQL limits table, column, index and constraint names to 64 characters. A longer name in CREATE TABLE stops with ERROR 1059, and the message quotes the whole name that was rejected.
Below, account lab_a hits the error twice: once with a 66-character table name and once with a 73-character foreign key name. CHAR_LENGTH confirmed both lengths, and the same statements worked after the names were shortened. Note that a too-long column alias in a view or a long unaliased expression in CREATE TABLE ... AS SELECT gives ERROR 1166, not 1059.
01The table name is longer than 64 characters
CREATE TABLE customer_order_shipping_address_history_for_internal_audit_2026_v2 (id INT PRIMARY KEY); failed with ERROR 1059. SELECT CHAR_LENGTH('customer_order_shipping_address_history_for_internal_audit_2026_v2') returned 66.
The table was created under the shorter name cust_ship_addr_hist_audit_2026, and SHOW TABLES listed it.
CREATE TABLE customer_order_shipping_address_history_for_internal_audit_2026_v2 (id INT PRIMARY KEY);ERROR 1059 (42000): Identifier name 'customer_order_shipping_address_history_for_internal_audit_2026_v2' is too longSELECT CHAR_LENGTH('customer_order_shipping_address_history_for_internal_audit_2026_v2') AS name_length;+-------------+
| name_length |
+-------------+
| 66 |
+-------------+
1 row in set (0.00 sec)Names generated by tools or ORMs (prefix + table + column + suffix) are the usual source. Check the length with CHAR_LENGTH before running the DDL.
CREATE TABLE cust_ship_addr_hist_audit_2026 (id INT PRIMARY KEY);
SHOW TABLES;Query OK, 0 rows affected (0.02 sec)
+--------------------------------+
| Tables_in_lab_a |
+--------------------------------+
| cust_ship_addr_hist_audit_2026 |
+--------------------------------+
1 row in set (0.00 sec)02The constraint (foreign key) name is longer than 64 characters
The table name itself was fine. The foreign key name fk_warehouse_inventory_transaction_line_items_txn_id_reference_constraint is 73 characters, and the whole CREATE TABLE failed with ERROR 1059 naming that constraint.
With CONSTRAINT fk_wh_inv_line_txn the same table was created, and information_schema.table_constraints showed the foreign key fk_wh_inv_line_txn.
Setup
CREATE TABLE warehouse_inventory_transactions (id INT PRIMARY KEY);Query OK, 0 rows affected (0.01 sec)CREATE TABLE warehouse_inventory_transaction_line_items (
id INT PRIMARY KEY,
txn_id INT,
CONSTRAINT fk_warehouse_inventory_transaction_line_items_txn_id_reference_constraint FOREIGN KEY (txn_id) REFERENCES warehouse_inventory_transactions (id)
);ERROR 1059 (42000): Identifier name 'fk_warehouse_inventory_transaction_line_items_txn_id_reference_constraint' is too longSELECT CHAR_LENGTH('fk_warehouse_inventory_transaction_line_items_txn_id_reference_constraint') AS name_length;+-------------+
| name_length |
+-------------+
| 73 |
+-------------+
1 row in set (0.00 sec)CREATE TABLE warehouse_inventory_transaction_line_items (
id INT PRIMARY KEY,
txn_id INT,
CONSTRAINT fk_wh_inv_line_txn FOREIGN KEY (txn_id) REFERENCES warehouse_inventory_transactions (id)
);
SELECT constraint_name FROM information_schema.table_constraints WHERE table_schema = 'lab_a' AND constraint_type = 'FOREIGN KEY';Query OK, 0 rows affected (0.02 sec)
+--------------------+
| CONSTRAINT_NAME |
+--------------------+
| fk_wh_inv_line_txn |
+--------------------+
1 row in set (0.00 sec)FAQ
What is the maximum length of a table name in MySQL?
64 characters. It is the same for column, index and constraint names. On this page a 66-character table name and a 73-character constraint name both gave ERROR 1059.
How do I find which name is too long?
The message quotes it: Identifier name '...' is too long. Check it with SELECT CHAR_LENGTH('name'); and shorten it to 64 characters or less.
Why does a long foreign key name fail the whole CREATE TABLE?
The constraint name is checked as part of the statement, so one long name stops the whole CREATE TABLE. Here the table name was short, but the 73-character CONSTRAINT name caused ERROR 1059.
Why did I get ERROR 1166 instead of 1059 for a long name?
For a column alias in CREATE VIEW, or an unaliased expression in CREATE TABLE ... AS SELECT, MySQL 8.4 reports a long name as Incorrect column name (1166). See the ERROR 1166 page.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13