I created 4 columns for a table
cur.execute("""CREATE TABLE videoinfo (
id INT UNSIGNED PRIMARY KEY AUTO INCREMENT,
date DATETIME NOT NULL,
src_ip CHAR(32),
hash CHAR(150));
""")
I have a .txt file which has three columns of data inside. I want to use LOAD DATA LOCAL INFILEcommand to insert data, but the problem is ,the table I created now has four columns, the first one is the id, so, can mysql automatically insert data from the second column or extra command is needed?
Many thanks!
AUTO INCREMENTisn’t valid syntax. If you check MySQL’s documentation for theCREATE TABLEstatement, you’ll see the proper keyword isAUTO_INCREMENT.Additionally,
dateis a keyword, so you’ll need to quote it with backticks, as mentioned on the MySQL identifier documentation page. The documentation also lists all keywords, which must be quoted to use them as identifiers. To be safe, you could simply quote all identifiers.To insert data only into some columns, you can explicitly specify columns. For
LOAD DATA INFILE:For the
INSERTstatement:This, too, is revealed in the MySQL manual. Notice a pattern?