简体   繁体   中英

mysql error; Error Code: 1136. Column count doesn't match value count at row 1

I am just learning MySQL and was trying to create a basic table. But I am getting this error; Error Code: 1136. Column count doesn't match value count at row 1.

use mydb ;
lock table user write;
insert into user(username,password,email,created,last_updated) values (
    ('TEST USERNAME','TEST PASSWORD','Test@test.com',current_timestamp(),current_timestamp()), 
    ('TEST USERNAME 2','TEST PASSWORD 2','Test2@test.com',current_timestamp(),current_timestamp())

);
unlock tables;

The columns in the table are (id,username,password,email,created,last_updated).Thanks.

Remove the brackets for Values(..) , ie , it should be Values (..), (..) instead.

insert into user(username,password,email,created,last_updated) 
values
('TEST USERNAME','TEST PASSWORD','Test@test.com',current_timestamp(),current_timestamp()), 
('TEST USERNAME 2','TEST PASSWORD 2','Test2@test.com',current_timestamp(),current_timestamp());

From Docs , the syntax is:

 INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [PARTITION (partition_name [, partition_name] ...)] [(col_name [, col_name] ...)] {VALUES | VALUE} (value_list) [, (value_list)] ... [ON DUPLICATE KEY UPDATE assignment_list] 

...

INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of comma-separated column values, with lists enclosed within parentheses and separated by commas. Example:

 INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9); 

your columns in your table has id yet you don't have it when you wrote

insert into user(username,password,email,created,last_updated)

you should write

insert into user(id,username,password,email,created,last_updated)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM