[Tutor] Creating MySQL table

Bernard Lebel 3dbernard at gmail.com
Mon Jul 18 22:00:38 CEST 2005


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"


oCursor.execute( sQuery )


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")



Any pointer would be appreciated.

Thanks
Bernard


More information about the Tutor mailing list