How to fix ERROR 1058: Column count doesn't match value count in MySQL

MySQLBEGINNERMEDIUMUpdated Dec 22, 2025· 219 views

This MySQL error occurs when an INSERT statement tries to insert data into a table, but the number of columns specified doesn't match the number of values provided. The error is a validation check that prevents inserting incomplete or misaligned data. The mismatch typically happens when you don't explicitly list column names and provide the wrong number of values, or when you list columns but provide a different count of values.

Quick fix

Fixes 1058

-- Step 1: Check your table structure and count columns
DESC users;
-- or
SHOW COLUMNS FROM users;

-- Output will show: id, name, email, age, created_at, etc.
-- Let's say this table has 5 columns total

-- Step 2: Look at your INSERT statement
INSERT INTO users VALUES ('John', 'john@email.com', 30);
-- You're providing 3 values but the table has 5 columns
-- This causes ERROR 1058

-- Step 3: Count the values in your VALUES clause
-- Correct: should have 5 values (one for each column)
INSERT INTO users VALUES (NULL, 'John', 'john@email.com', 30, NOW());
-- NULL for auto-increment id, name, email, age, created_at
  1. Count your columns and values explicitly
  2. Use explicit column names (recommended fix)
  3. Handle auto-increment columns correctly
  4. Check for trailing commas and syntax errors
mysql — error
-- Step 1: Check your table structure and count columns
DESC users;
-- or
SHOW COLUMNS FROM users;
-- Output will show: id, name, email, age, created_at, etc.
-- Let's say this table has 5 columns total
-- Step 2: Look at your INSERT statement
INSERT INTO users VALUES ('John', 'john@email.com', 30);
-- You're providing 3 values but the table has 5 columns
-- This causes ERROR 1058
-- Step 3: Count the values in your VALUES clause
-- Correct: should have 5 values (one for each column)
INSERT INTO users VALUES (NULL, 'John', 'john@email.com', 30, NOW());
-- NULL for auto-increment id, name, email, age, created_at
ERROR 1058: Column count doesn't match value count

What this error means

Error 1058 "Column count doesn't match value count" is MySQL's validation error that fires during the INSERT statement parsing phase. This error occurs for several reasons: 1. **Implicit Column Count**: When you don't specify column names in an INSERT statement, MySQL expects values for ALL columns in the table, in the order they're defined in the table schema. If you provide fewer or more values than the total column count, the error occurs. 2. **Explicit Column Count Mismatch**: When you explicitly list columns (e.g., `INSERT INTO users (name, email) VALUES (...)`) but provide a different number of values than columns listed, the error fires. For example, 2 columns but 3 values, or 3 columns but 2 values. 3. **Auto-Increment Column Confusion**: Auto-increment columns still count in the total column count. If you don't specify the column list and forget to include a value (or placeholder like NULL/DEFAULT) for the auto-increment column, you'll have a mismatch. 4. **Hidden Columns**: Some MySQL features add hidden columns that must be accounted for. Partitioned tables or columns with special attributes might not be obvious in the column count. 5. **Default Values**: Columns with DEFAULT values can be omitted from the column list, but they must still be accounted for if you're not specifying columns explicitly. Unlike runtime errors, this is a structural validation error - MySQL checks the syntax before executing the INSERT.

Typical symptoms

  • Error message appears: "ERROR 1058: Column count doesn't match value count"
  • Error occurs during INSERT statement execution
  • Application fails when trying to save data to database
  • ORM or database client shows this error when attempting create/insert operations
  • Works for some rows but fails for others (partial insert)
  • Error message may show "at row 1" or specify which row caused the issue
  • Bulk imports (LOAD DATA INFILE) fail partway through
  • Script stops at specific INSERT statement without executing the query

Common causes

  1. INSERT statement without explicit column list provides wrong number of values compared to table column count
  2. Explicit column list has different count than values in VALUES clause
  3. Forgot to include value for auto-increment (primary key) column when not specifying columns
  4. Extra trailing comma in VALUES clause creates an empty placeholder value
  5. Missing values for columns that don't have DEFAULT values
  6. Column list includes more columns than values (or vice versa)
  7. Typo in column list or values clause that results in count mismatch
  8. Copying query from different table with different column structure
  9. Dynamic query construction forgot to account for all columns
  10. Multi-row INSERT with inconsistent value counts per row

How to fix "ERROR 1058: Column count doesn't match value count"

1Count your columns and values explicitly

First, identify exactly how many columns your table has and how many values you're providing:

sql
-- Step 1: Check your table structure and count columns
DESC users;
-- or
SHOW COLUMNS FROM users;

-- Output will show: id, name, email, age, created_at, etc.
-- Let's say this table has 5 columns total

-- Step 2: Look at your INSERT statement
INSERT INTO users VALUES ('John', 'john@email.com', 30);
-- You're providing 3 values but the table has 5 columns
-- This causes ERROR 1058

-- Step 3: Count the values in your VALUES clause
-- Correct: should have 5 values (one for each column)
INSERT INTO users VALUES (NULL, 'John', 'john@email.com', 30, NOW());
-- NULL for auto-increment id, name, email, age, created_at

Manually count both: if they don't match, you've found the issue.

2Use explicit column names (recommended fix)

The best fix is to explicitly specify which columns you're inserting into. This way, omitted columns use their DEFAULT values:

sql
-- WRONG: Relies on knowing exact column order and count
INSERT INTO users VALUES ('John', 'john@email.com', 30);
-- ERROR 1058!

-- CORRECT: Explicitly list columns you're inserting
INSERT INTO users (name, email, age) VALUES ('John', 'john@email.com', 30);
-- Works! id auto-increments, created_at uses DEFAULT

-- ALSO CORRECT: List all columns with appropriate values
INSERT INTO users (id, name, email, age, created_at) 
VALUES (NULL, 'John', 'john@email.com', 30, NOW());
-- NULL lets id auto-increment, NOW() for created_at

When you explicitly list columns, only those columns need values, and the order is clear in your code.

3Handle auto-increment columns correctly

Auto-increment primary keys are a common source of this error. Handle them with NULL or DEFAULT:

sql
-- If table has: id (AUTO_INCREMENT), name, email

-- WRONG: Only 2 values but table has 3 columns
INSERT INTO users VALUES ('John', 'john@email.com');
-- ERROR 1058

-- CORRECT: Use NULL to auto-generate the id
INSERT INTO users VALUES (NULL, 'John', 'john@email.com');
-- or
INSERT INTO users VALUES (DEFAULT, 'John', 'john@email.com');
-- or (best practice)
INSERT INTO users (name, email) VALUES ('John', 'john@email.com');
-- Omit the id column entirely when using explicit list

-- For bulk inserts
INSERT INTO users (name, email) VALUES 
  ('John', 'john@email.com'),
  ('Jane', 'jane@email.com'),
  ('Bob', 'bob@email.com');
-- Each row needs the same number of values as columns listed

Always use NULL or omit auto-increment columns in your column list.

4Check for trailing commas and syntax errors

Trailing commas or parentheses issues can create phantom columns:

sql
-- WRONG: Trailing comma creates 4 "values" (last is empty)
INSERT INTO users (name, email, age,) VALUES ('John', 'john@email.com', 30,);
-- The trailing commas cause parsing issues

-- CORRECT: No trailing commas
INSERT INTO users (name, email, age) VALUES ('John', 'john@email.com', 30);

-- WRONG: Mismatched parentheses
INSERT INTO users (name, email, age) VALUES ('John', 'john@email.com', 30));
-- Extra closing paren

-- CORRECT
INSERT INTO users (name, email, age) VALUES ('John', 'john@email.com', 30);

-- WRONG: Multi-row insert with inconsistent columns per row
INSERT INTO users (name, email) VALUES 
  ('John', 'john@email.com'),
  ('Jane', 'jane@email.com', 'extra');  -- 3rd value in 2nd row!
-- ERROR 1058

-- CORRECT: Same column count per row
INSERT INTO users (name, email) VALUES 
  ('John', 'john@email.com'),
  ('Jane', 'jane@email.com');  -- Consistent 2 values per row

Carefully check for syntax errors and ensure every row in multi-row inserts has the same count.

5Verify column definitions and defaults

Sometimes columns have DEFAULT values that can affect the count logic:

sql
-- Check your table structure in detail
DESC users;
-- Look at the "Default" and "Null" columns

-- Example output:
-- Field     Type      Null  Key  Default       Extra
-- id        int       NO    PRI  NULL          auto_increment
-- name      varchar   NO         NULL
-- email     varchar   NO         NULL
-- age       int       YES        NULL
-- is_active tinyint   NO         1              -- Has DEFAULT
-- created_at timestamp NO        CURRENT_TIMESTAMP -- Has DEFAULT

-- Columns with DEFAULT can be omitted from INSERT:
INSERT INTO users (name, email, age) VALUES ('John', 'john@email.com', 30);
-- is_active gets DEFAULT 1, created_at gets CURRENT_TIMESTAMP

-- Columns with NULL YES can use NULL:
INSERT INTO users (name, email, age, is_active) VALUES ('John', 'john@email.com', NULL, 1);
-- age is NULL instead of a number

-- If a column is NOT NULL and has no DEFAULT, you must provide it:
-- This would ERROR:
INSERT INTO users (name) VALUES ('John');
-- Because email, age (and others) are NOT NULL

Use SHOW CREATE TABLE or DESC to see which columns have defaults and which allow NULL.

6Test with explicit column list first

When debugging this error, always use explicit column lists to isolate the issue:

sql
-- Start simple: just essential columns
INSERT INTO users (name, email) VALUES ('John', 'john@email.com');
-- This works and establishes baseline

-- Add one column at a time
INSERT INTO users (name, email, age) VALUES ('John', 'john@email.com', 30);
-- Still works

INSERT INTO users (name, email, age, country) VALUES ('John', 'john@email.com', 30, 'USA');
-- Works or fails here - you know which column caused it

-- Once you get the working format, you can use it as a template
-- for bulk inserts or code generation

-- When using ORMs or frameworks, they typically handle this:
-- Sequelize (Node.js):
User.create({ name: 'John', email: 'john@email.com' });
-- ORM constructs the column list automatically

-- Django (Python):
User.objects.create(name='John', email='john@email.com')
# ORM handles mapping

-- Always test raw SQL separately if your ORM has issues

Using explicit columns is the safest debugging approach.

7Fix bulk/LOAD DATA imports

LOAD DATA INFILE and bulk imports have special requirements for column matching:

sql
-- LOAD DATA requires column count to match file column count
-- CSV file has: name,email,age (3 columns)

-- WRONG: Table has 5 columns but specifying only 3
LOAD DATA INFILE '/path/to/file.csv'
INTO TABLE users
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
-- ERROR 1058 if there are 5 table columns but only 3 in file

-- CORRECT: Explicitly specify which columns from file go where
LOAD DATA INFILE '/path/to/file.csv'
INTO TABLE users (name, email, age)
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
-- Now it matches: 3 columns in file, 3 in column list

-- ALSO CORRECT: File has values for all columns
LOAD DATA INFILE '/path/to/file.csv'
INTO TABLE users
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
-- File should have: id,name,email,age,created_at (5 columns)
-- Matching all 5 table columns

-- Check file column count:
head -1 /path/to/file.csv | tr ',' '\n' | wc -l
-- This shows how many comma-separated columns are in the file

-- Check table column count:
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = 'users' AND TABLE_SCHEMA = 'your_database';
-- These two numbers must match if not using explicit column list

For LOAD DATA, ensure file column count matches table columns or explicitly specify which columns.

Advanced notes

Understanding ERROR 1058 in depth helps avoid it in application code:

1. Column Ordering Matters: MySQL matches values to columns by position, not by name. The first value goes to the first column, second to second, etc. This is why explicit column lists are so much safer.

2. NULL vs DEFAULT: When you provide NULL in the VALUES clause, it explicitly sets that column to NULL (if the column allows NULL). When you omit a column entirely from the column list, it gets its DEFAULT value. These are different behaviors.

3. Generated Columns: MySQL 5.7+ supports generated columns (GENERATED ALWAYS AS). These columns cannot be inserted into - they compute their values automatically. If you try to include them in your column list or value count, you get an error.

4. View INSERT Rules: When inserting into a VIEW instead of a table, the column matching is different. Views can have INSTEAD OF triggers that redirect inserts. The view definition must allow INSERT and columns must match.

5. Partition-Related Issues: Tables with PARTITION clauses still require the same column count. The partition column is not "hidden" - it must be accounted for in the value count.

6. Character Set and Encoding: Column count is not affected by character sets, but inserting the wrong character encoding (e.g., binary into text) can cause related errors.

7. JSON Columns and NULL: JSON columns can store NULL or JSON data. If you have a JSON column and provide NULL, that counts as one value. Omitting it gives it NULL by DEFAULT.

8. Performance Implications: Multi-row inserts (batch inserts) are much faster than single-row inserts, but they require strict column consistency across all rows, making this error more common with bulk operations.

9. Application Code Generation: Many frameworks auto-generate INSERT statements. If your ORM has a bug or configuration issue, it might generate mismatched column/value counts. Always inspect generated SQL when debugging.

10. Prepared Statements: Using prepared statements in your application (e.g., mysqli prepared statements, PDO prepared statements) prevents this error because the database parses the column structure separately from values. Always use prepared statements in production code.

Frequently asked questions

What does "1058" mean?
Error 1058 "Column count doesn't match value count" is MySQL's validation error that fires during the INSERT statement parsing phase. This error occurs for several reasons: 1. Implicit Column Count: When you don't specify column names in an INSERT statement, MySQL expects values for ALL columns in the table, in the order they're defined in the table schema.
How do I fix "1058"?
This MySQL error occurs when an INSERT statement tries to insert data into a table, but the number of columns specified doesn't match the number of values provided. The error is a validation check that prevents inserting incomplete or misaligned data. The mismatch typically happens when you don't explicitly list column names and provide the wrong number of values, or when you list columns but provide a different count of values.
What causes "1058"?
INSERT statement without explicit column list provides wrong number of values compared to table column count Explicit column list has different count than values in VALUES clause Forgot to include value for auto-increment (primary key) column when not specifying columns
Is the "1058" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading