Hello,<br>
<br>
I am currenty using MySQL 5.1 community server and trying to import the
data of the comma delimited text file into the table using python 2.6
scripts. I have installed Mysqldb 1.2.2. <br>
<br>
follwoing is my script:<br>
<br>
<br>
<br><div class="codeblock"><div class="ad_notxt"> <div id="code42581772_1"><pre class="code"><ol><li class="li1"><div class="de1"><span class="kw1">import</span> MySQLdb, <span class="kw3">csv</span>, <span class="kw3">sys</span></div>
</li><li class="li1"><div class="de1">conn = MySQLdb.<span class="me1">connect</span> <span class="br0">(</span>host = <span class="st0">"localhost"</span>,<span class="kw3">user</span> = <span class="st0">"usr"</span>, passwd = <span class="st0">"pass"</span>,db = <span class="st0">"databasename"</span><span class="br0">)</span></div>
</li><li class="li1"><div class="de1">c = conn.<span class="me1">cursor</span><span class="br0">(</span><span class="br0">)</span></div></li><li class="li1"><div class="de1">csv_data=<span class="kw3">csv</span>.<span class="me1">reader</span><span class="br0">(</span><span class="kw2">file</span><span class="br0">(</span><span class="st0">"a.txt"</span><span class="br0">)</span><span class="br0">)</span></div>
</li><li class="li2"><div class="de2"><span class="kw1">for</span> row <span class="kw1">in</span> csv_data:</div></li><li class="li1"><div class="de1">  <span class="kw1">print</span> row</div></li><li class="li1"><div class="de1">
        c.<span class="me1">execute</span><span class="br0">(</span><span class="st0">"INSERT INTO a (first, last) VALUES (%s, %s), row"</span><span class="br0">)</span></div></li><li class="li1"><div class="de1">c.<span class="me1">commit</span><span class="br0">(</span><span class="br0">)</span></div>
</li><li class="li1"><div class="de1">c.<span class="me1">close</span><span class="br0">(</span><span class="br0">)</span></div></li></ol></pre></div> <div id="code42581772_2" style="display: none;"><textarea class="code" readonly style="height: 162px;">import MySQLdb, csv, sys
conn = MySQLdb.connect (host = "localhost",user = "usr", passwd = "pass",db = "databasename")
c = conn.cursor()
csv_data=csv.reader(file("a.txt"))
for row in csv_data:
        print row
        c.execute("INSERT INTO a (first, last) VALUES (%s, %s), row")
c.commit()
c.close()</textarea></div> </div> </div><br>
the contents of the text file eg. :<br>
-----------------<br>
John,Smith<br>
Danie,Thomas<br>
Ronald,Rey<br>
--------------------<br>
<br>
When I execute the statement I get the following error:<br>
------------------------------------------------------------------------------------<br>
C:\Python26\lib\site-packages\MySQLdb\__init__.py:34: DeprecationWarning: the sets module is deprecate<br>
d<br>
  from sets import ImmutableSet<br>
['John', 'Smith']<br>
Traceback (most recent call last):<br>
  File "e:\Scripts\test.py", line 10, in <module><br>
    c.execute("INSERT INTO a (first, last) VALUES (%s, %s), row")<br>
  File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 166, in execute<br>
    self.errorhandler(self, exc, value)<br>
  File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler<br>
    raise errorclass, errorvalue<br>
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual tha<br>
t corresponds to your MySQL server version for the right syntax to use near '%s, %s), row' at line 1")<br>
------------------------------------------------------------------------------------<br>
<br>
Any kind of help to get me going will be greatly appreciated.