“Column count doesn't match value count at row” but it does

前端 未结 7 1719
我在风中等你
我在风中等你 2020-12-30 00:11

I\'ve got a mysql file with over than 14000 statements. All of them are inserts into a table, and when I import the file using console, it throws the following error:

<
相关标签:
7条回答
  • 2020-12-30 00:36

    I met the same issue too. @valplo's answer is right. Since I don't have enough reputation to comment, I write it here.

    The correct way to insert multiple values is to list the values after the key word VALUES, not parenthesis around multiple value entries, but parenthesis around single value entries, and separate each single value entry with comma.

    The wrong way is:

    INSERT INTO my_table(column_name_0, column_name_1) VALUES(
        (val_00, val_01),
        (val_10, val_11)
    );
    

    The correct way is:

    INSERT INTO my_table(column_name_0, column_name_1) VALUES
        (val_00, val_01),
        (val_10, val_11);
    
    0 讨论(0)
  • 2020-12-30 00:41

    I was facing a similar error. It was just the matter of a missing comma. Check if all the items in the insert statement are separated by commas

    0 讨论(0)
  • 2020-12-30 00:46

    Check for special hidden characters in the file. You might think that all whitespace in the file are spaces, but sometimes other characters can kill the insert in some way you can't understand by looking at the data.

    If all else fails, retype the INSERT manually and run it in a file by itself to see if it still fails.

    0 讨论(0)
  • 2020-12-30 00:46

    In my case it was the number of "?" in the prepared statement

    prepare stmt1 from  "insert into company (name, address, phone) values(?,?);";
    /*note only 2 question marks which should be 3.*/
    

    This also will trigger the same error

    insert into company (name, address, phone) values('foo','bar');
    
    0 讨论(0)
  • 2020-12-30 00:47

    In my case I had a trigger on INSERT with column mismatch count :(&

    0 讨论(0)
  • 2020-12-30 00:50

    I faced a similar problem because of inserting parenthesis around data :-(:

    INSERT INTO Customers (Name,LastCredit,CreditDate) VALUES ( <-- Here.
        ("Nuclear Millitary Systems",500.0,CURRENT_DATE),
        ("Evil Corporation",67890.95,"2012-02-12"),
        ("Nuke Software Systems",5600.0,"2013-05-06"),
        ("RR Millitary",600.0,"2013-05-06"),
        ("Random Automation",560.0,"2012-05-01"),
        ("Evil Data Systems",600.0,"2013-03-01")
      ); 
    
    0 讨论(0)
提交回复
热议问题