Reputation: 233
I've got a CSV excel file, which one I want to convert into mysqldb.
It is working very fine, but in every cell in the MYSQLdb there are unnecessary quotation marks, like this: ""
.
When the cell is empty I see this: ""
When the cell is not empty is see this: "somethingdata"
I can't understand, why put these quotation marks when in the csv file there are none.
Here my code, I think it is correct too.
connection = MySQLdb.connect(host='localhost',
user='root',
passwd='1234',
db='database')
cursor = connection.cursor()
query = """
CREATE TABLE `test` (
`Megnevezes` varchar(100) DEFAULT NULL,
`2015` varchar(100) DEFAULT NULL,
`2014` varchar(100) DEFAULT NULL,
`2013` varchar(100) DEFAULT NULL,
`2012` varchar(100) DEFAULT NULL,
`2011` varchar(100) DEFAULT NULL,
`ID` int(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8"""
cursor.execute(query)
connection.commit()
cursor.close()
connection = MySQLdb.connect(host='localhost',
user='root',
passwd='1234',
db='database')
cursor = connection.cursor()
query = """ load data local infile 'C:/Python27/output.csv'
into table test
character set latin1
fields terminated by ';'
lines terminated by '\n'
ignore 1 lines;
"""
cursor.execute(query)
connection.commit()
cursor.close()
Any ideas how can I fix this issue?
Upvotes: 0
Views: 24
Reputation: 821
https://dev.mysql.com/doc/refman/5.7/en/load-data.html
Use the: ENCLOSED BY 'char'
where char will be "
Upvotes: 1