[Tutor] Creating MySQL table

Don Parris gnumathetes at gmail.com
Mon Jul 18 23:36:09 CEST 2005


On 7/18/05, Bernard Lebel <3dbernard at gmail.com> wrote:
> Hello,
> 
> How do I create a MySQL table in Python?
> 
> Here is what I'm trying:
> 
> 
> import MySQLdb as sql
> 
> def connect2db():
>       return sql.connect( blah blah blah )
> 
> 
> oConnection = connect2db()
> oCursor = oConnection.cursor()
> 
> 
> sQuery = "CREATE TABLE '3DPipeline'.'TB_MT_NAME' (;\
>   'ID' INTEGER UNSIGNED CHARACTER SET latin1 COLLATE latin1_swedish_ci
> NOT NULL AUTO_INCREMENT,
>   'text' TINYTEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
>   PRIMARY KEY('ID')
> )
> ENGINE = InnoDB"
> 
> 
Looking above, I'm not sure why there's a "." after 3DPipeline.  Also,
the ";" should be placed after the last command before the closing
parenthesis, not at the beginning.  I have no idea about your use of
the backslash.


> When I run that, I get this:
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "D:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 137, in execute
>     self.errorhandler(self, exc, value)
>   File "D:\Python24\Lib\site-packages\MySQLdb\connections.py", line
> 33, in defaulterrorhandler
>     raise errorclass, errorvalue
> _mysql_exceptions.ProgrammingError: (1064, "You have an error in your
> SQL syntax; check the manual that corresponds to your MySQL server
> version for the right syntax to use near ''3DPipline'.'TB_MT_NAME' (
> 'ID' INTERGER UNSIGNED CHARACTER SET latin1 COLLATE l' at line 1")
> 
> 
This error message points to your SQL syntax.  Notice that it wants
you to check "your MySQL server version for the right syntax to use". 
That should alert you to the fact that your SQL syntax is incorrect.

HTH,
Don
-- 
DC Parris GNU Evangelist
http://matheteuo.org/
gnumathetes at gmail.com
Free software is like God's love - 
you can share it with anyone anywhere anytime!


More information about the Tutor mailing list