Python的mysql.connector给了我ProgrammingError:1064(42000)

时间:2020-07-08 05:23:07

标签: python mysql

嗨,有人可以在这里检查我的语法错误吗?我试图在python的mysql.connector中创建一个表,但是无论我做了什么更改,都不断遇到相同的错误。

CREATE TABLE IF NOT EXISTS #TTC (
        City varchar(255),
        LastName varchar(255),
        FirstName varchar(255), 
        Address varchar(255), 
        PersonID int,
        LastNameee varchar(255),
        LaaaaaastName varchar(255),
        LasssssstName varchar(255),
);

在较大的程序中运行这段代码,我不断收到错误消息,

MySQLInterfaceError                       Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/connection_cext.py in cmd_query(self, query, raw, buffered, raw_as_string)
    486                 query = query.encode('utf-8')
--> 487             self._cmysql.query(query,
    488                                raw=raw, buffered=buffered,

MySQLInterfaceError: 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 'varchar(255),
        LastName varchar(255),
        FirstName varchar(255), 
' at line 2

During handling of the above exception, another exception occurred:

ProgrammingError                          Traceback (most recent call last)
<ipython-input-29-9ae0d306f12e> in <module>
     13     print(create_table)
     14 
---> 15     cursor.execute(create_table)

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/cursor_cext.py in execute(self, operation, params, multi)
    262 
    263         try:
--> 264             result = self._cnx.cmd_query(stmt, raw=self._raw,
    265                                          buffered=self._buffered,
    266                                          raw_as_string=self._raw_as_string)

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/connection_cext.py in cmd_query(self, query, raw, buffered, raw_as_string)
    489                                raw_as_string=raw_as_string)
    490         except MySQLInterfaceError as exc:
--> 491             raise errors.get_mysql_exception(exc.errno, msg=exc.msg,
    492                                              sqlstate=exc.sqlstate)
    493         except AttributeError:

ProgrammingError: 1064 (42000): 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 'varchar(255),
        LastName varchar(255),
        FirstName varchar(255), 
' at line 2

1 个答案:

答案 0 :(得分:2)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Error: Bad Request<br> &nbsp; &nbsp;at /Users/nrb/Development/Borduhh/SaasyNode/server/dist/app.js: 39: 25<br> &nbsp; &nbsp;at Layer.handle [as handle_request
] (/Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/express/lib/router/layer.js: 95: 5)<br> &nbsp; &nbsp;at trim_prefix (/Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/express/lib/router/index.js: 317: 13)<br> &nbsp; &nbsp;at /Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/express/lib/router/index.js: 284: 7<br> &nbsp; &nbsp;at Function.process_params (/Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/express/lib/router/index.js: 335: 12)<br> &nbsp; &nbsp;at next (/Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/express/lib/router/index.js: 275: 10)<br> &nbsp; &nbsp;at /Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/body-parser/lib/read.js: 130: 5<br> &nbsp; &nbsp;at invokeCallback (/Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/raw-body/index.js: 224: 16)<br> &nbsp; &nbsp;at done (/Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/raw-body/index.js: 213: 7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/Users/nrb/Development/Borduhh/SaasyNode/server/node_modules/raw-body/index.js: 273: 7)</pre>
</body>
</html>

我可能会弄错了,但似乎不是逗号,而是其他一些看起来像字符的逗号?