Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-30 · container image mysql:8.4
ERROR 1166 means the name of a column about to be created is not allowed. The message quotes that name, which may be a name you typed or one MySQL derived from an expression.
Below, account lab_a hits it three ways: an unaliased 66-character expression in CREATE TABLE ... AS SELECT, a column name with a trailing space, and a 68-character column alias in CREATE VIEW. Two of these are "name too long" cases, yet MySQL 8.4 reports them as 1166, not ERROR 1059 (Identifier name is too long). Each one worked after giving the column a short or clean name.
01An expression without an alias in CREATE TABLE ... AS SELECT
CREATE TABLE customer_labels AS SELECT id, CONCAT(first_name, ' ', last_name, ' (', city, ')', ' - customer') FROM customers; failed. Without an alias, the expression text itself becomes the column name, and the message quotes it. CHAR_LENGTH of that text was 66.
Adding AS label fixed it: the table was created with 2 rows, such as Minji Kim (Seoul) - customer.
Setup
CREATE TABLE customers (id INT PRIMARY KEY, first_name VARCHAR(20), last_name VARCHAR(20), city VARCHAR(20));
INSERT INTO customers VALUES (1, 'Minji', 'Kim', 'Seoul'), (2, 'Jun', 'Lee', 'Busan');Query OK, 0 rows affected (0.02 sec)
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0CREATE TABLE customer_labels AS
SELECT id, CONCAT(first_name, ' ', last_name, ' (', city, ')', ' - customer') FROM customers;ERROR 1166 (42000): Incorrect column name 'CONCAT(first_name, ' ', last_name, ' (', city, ')', ' - customer')'SELECT CHAR_LENGTH('CONCAT(first_name, '' '', last_name, '' ('', city, '')'', '' - customer'')') AS expression_length;+-------------------+
| expression_length |
+-------------------+
| 66 |
+-------------------+
1 row in set (0.00 sec)Give every expression an alias in CREATE TABLE ... AS SELECT. It also keeps the new table's column names readable.
CREATE TABLE customer_labels AS
SELECT id, CONCAT(first_name, ' ', last_name, ' (', city, ')', ' - customer') AS label FROM customers;
SELECT * FROM customer_labels;Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
+----+------------------------------+
| id | label |
+----+------------------------------+
| 1 | Minji Kim (Seoul) - customer |
| 2 | Jun Lee (Busan) - customer |
+----+------------------------------+
2 rows in set (0.00 sec)02A column name ends with a space
In CREATE TABLE upload_rows, the backtick-quoted column 'customer name ' has a space at the end, and the statement failed with Incorrect column name 'customer name '. Wrapping the name in brackets made the space visible: [customer name ] vs [customer name] after TRIM.
With customer_name the table was created, and SHOW COLUMNS listed order_no and customer_name.
CREATE TABLE upload_rows (
`order_no` INT,
`customer name ` VARCHAR(50)
);ERROR 1166 (42000): Incorrect column name 'customer name 'SELECT CONCAT('[', 'customer name ', ']') AS raw_name, CONCAT('[', TRIM('customer name '), ']') AS trimmed;+------------------+-----------------+
| raw_name | trimmed |
+------------------+-----------------+
| [customer name ] | [customer name] |
+------------------+-----------------+
1 row in set (0.00 sec)This often comes from column names copied out of a spreadsheet or CSV header. Trim them before generating DDL.
CREATE TABLE upload_rows (
`order_no` INT,
`customer_name` VARCHAR(50)
);
SHOW COLUMNS FROM upload_rows;Query OK, 0 rows affected (0.01 sec)
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| order_no | int | YES | | NULL | |
| customer_name | varchar(50) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)03A view column alias is longer than 64 characters
CREATE VIEW order_summary AS SELECT SUM(amount) AS total_order_amount_including_tax_and_shipping_for_all_customers_2026 FROM orders; failed with ERROR 1166. The alias is 68 characters. It is a too-long name, but the error is 1166, not 1059.
With AS total_order_amount the view was created, and SELECT * FROM order_summary returned 3500.
Setup
CREATE TABLE orders (id INT PRIMARY KEY, amount INT);
INSERT INTO orders VALUES (1, 1000), (2, 2500);Query OK, 0 rows affected (0.01 sec)
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0CREATE VIEW order_summary AS
SELECT SUM(amount) AS total_order_amount_including_tax_and_shipping_for_all_customers_2026 FROM orders;ERROR 1166 (42000): Incorrect column name 'total_order_amount_including_tax_and_shipping_for_all_customers_2026'SELECT CHAR_LENGTH('total_order_amount_including_tax_and_shipping_for_all_customers_2026') AS alias_length;+--------------+
| alias_length |
+--------------+
| 68 |
+--------------+
1 row in set (0.00 sec)CREATE VIEW order_summary AS
SELECT SUM(amount) AS total_order_amount FROM orders;
SELECT * FROM order_summary;Query OK, 0 rows affected (0.00 sec)
+--------------------+
| total_order_amount |
+--------------------+
| 3500 |
+--------------------+
1 row in set (0.00 sec)FAQ
What causes Incorrect column name in MySQL?
The name of a column being created is invalid. On this page it came from an unaliased long expression in CREATE TABLE AS SELECT, a name with a trailing space, and a view alias over 64 characters.
Why does CREATE TABLE AS SELECT fail with ERROR 1166?
An expression without an alias uses its own text as the column name. Here that text was 66 characters, over the 64 limit. Add an alias such as AS label.
What is the difference between ERROR 1059 and ERROR 1166?
Both can be about long names. On MySQL 8.4 a long table or constraint name gave 1059 (Identifier name is too long), while a long view column alias or unaliased CTAS expression gave 1166 (Incorrect column name).
Can a MySQL column name end with a space?
No. 'customer name ' with a trailing space gave ERROR 1166. The name customer_name worked.
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