Note that there are some explanatory texts on larger screens.

plurals
  1. POimport csv file into Mysql Database using python
    primarykey
    data
    text
    <p>This is my code:</p> <pre><code>#!/usr/bin/python import MySQLdb import csv db = MySQLdb.connect(host="host", # The Host user="username", # username passwd="pwd", # password db="databasename") # name of the data base sqlLoadData = 'LOAD DATA LOCAL INFILE "csv?_file_name.csv" INTO TABLE tablename ' sqlLoadData += 'FIELDS TERMINATED BY "," LINES TERMINATED BY "\n"' sqlLoadData += 'IGNORE 1 LINES' sqlLoadData += 'ENCLOSED BY '"' ESCAPED BY "\\" ' try: curs = db.cursor() curs.execute(sqlLoadData) resultSet = curs.fetchall() except StandardError, e: print e db.rollback() db.close() </code></pre> <p>I recieve the error Message : You have an error in your SQL Syntax; chekc the manual that correcpond to your Mysql Server.</p> <p>When I remove the part <code>sqlLoadData += 'ENCLOSED BY '"' ESCAPED BY "\\" '</code> everything work perfect. I used the last part just to remove the quote from the values.</p> <p>I also tried:</p> <blockquote> <p>cursor = mydb.cursor()</p> <p>reader = csv.reader(open('Cumulative.csv', 'rb'))</p> <p>reader.next() for row in reader[1:]: cursor.execute('INSERT INTO Cumulative (C1, C2, C3, C4, C5, C6) VALUES(%s, %s, %s, %s, %s, %s)', row)<br> cursor.commit() </p> </blockquote> <p>close the connection to the database. </p> <blockquote> <p>cursor.close()</p> </blockquote> <p>I want just to remove the quote so the integer field will support the data. so with quote "1" will be considered as a String instead of integer</p> <p>Can Anyone please help me to understand this?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload