실제 DB 검증MySQL 8.4.13에서 재현·해결 확인 · 2026-11-30 · 컨테이너 이미지 mysql:8.4
ERROR 1166은 새로 만들 컬럼 이름이 허용되지 않는다는 뜻이에요. 메시지에 그 이름이 찍히는데, 직접 쓴 이름일 수도 있고 MySQL이 식에서 자동으로 만든 이름일 수도 있어요. MySQL에 이 에러의 한국어 번역이 없어 메시지는 영어로 나와요.
아래 실험에서 lab_a 계정이 세 가지로 이 에러를 만났어요. CREATE TABLE ... AS SELECT의 별칭 없는 66자 식, 끝에 공백이 붙은 컬럼명, CREATE VIEW의 68자 컬럼 별칭이에요. 이 중 두 개는 '이름이 너무 긴' 경우인데도 MySQL 8.4는 ERROR 1059(Identifier name is too long)가 아니라 1166으로 알려 줘요. 모두 컬럼 이름을 짧고 깔끔하게 바꾸자 성공했어요.
01CREATE TABLE ... AS SELECT에서 식에 별칭 없음
CREATE TABLE customer_labels AS SELECT id, CONCAT(first_name, ' ', last_name, ' (', city, ')', ' - customer') FROM customers;가 실패했어요. 별칭이 없으면 식 문자열이 그대로 컬럼 이름이 되는데, 메시지에도 그 식이 찍혔어요. 그 문자열을 CHAR_LENGTH로 재 보니 66자였어요.
AS label을 붙이자 테이블이 만들어졌고 Minji Kim (Seoul) - customer 같은 2행이 들어갔어요.
사전 준비
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)CREATE TABLE ... AS SELECT에서는 식마다 별칭을 붙이세요. 새 테이블 컬럼 이름도 알아보기 쉬워져요.
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)02컬럼 이름 끝에 공백
CREATE TABLE upload_rows에서 백틱으로 감싼 'customer name ' 끝에 공백이 있어서 Incorrect column name 'customer name '으로 실패했어요. 대괄호로 감싸 보면 [customer name ], TRIM 후에는 [customer name]으로 공백이 눈에 보여요.
customer_name으로 바꾸자 테이블이 만들어졌고 SHOW COLUMNS에 order_no, 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)엑셀이나 CSV 헤더를 복사해 컬럼명을 만들 때 자주 생겨요. 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)03뷰 컬럼 별칭이 64자 초과
CREATE VIEW order_summary AS SELECT SUM(amount) AS total_order_amount_including_tax_and_shipping_for_all_customers_2026 FROM orders;가 ERROR 1166으로 실패했어요. 별칭이 68자예요. 이름이 너무 긴 경우지만 1059가 아니라 1166이 나요.
AS total_order_amount로 줄이자 뷰가 만들어졌고 SELECT * FROM order_summary가 3500을 돌려줬어요.
사전 준비
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)자주 묻는 질문
MySQL Incorrect column name 에러 원인이 뭐예요?
만들려는 컬럼 이름이 잘못됐다는 뜻이에요. 이 페이지에서는 CREATE TABLE AS SELECT의 별칭 없는 긴 식, 끝에 공백이 있는 이름, 64자 넘는 뷰 별칭에서 났어요.
CREATE TABLE AS SELECT 할 때 1166이 나요
별칭 없는 식은 식 문자열 자체가 컬럼 이름이 돼요. 여기서는 그 길이가 66자로 64자 한도를 넘었어요. AS label처럼 별칭을 붙이면 돼요.
ERROR 1059와 1166 차이가 뭐예요?
둘 다 긴 이름 때문에 날 수 있어요. MySQL 8.4에서 테이블명·제약조건 이름이 길면 1059(Identifier name is too long), 뷰 컬럼 별칭이나 CTAS의 별칭 없는 식이 길면 1166(Incorrect column name)이 났어요.
MySQL 컬럼명 끝에 공백을 넣을 수 있나요?
안 돼요. 끝에 공백이 있는 'customer name '은 ERROR 1166으로 실패했고, customer_name은 성공했어요.
검증 방법
시나리오마다 새 DB 사용자를 만들어 시작해요. 스크립트가 사전 준비 → 에러 재현(에러 코드 일치 확인) → 해결 → 원래 문장 재실행 순서로 실행하고, 화면의 출력은 DB가 실제로 낸 결과를 스크립트가 그대로 저장한 거예요.
lab_a, lab_b는 테스트용 일반 사용자(같은 이름의 데이터베이스가 기본, 그 안에서 모든 권한), root는 관리자예요. MySQL 8.4.13