Pycharm 中的代码:
import MySQLdb
db = MySQLdb.connect("127.0.0.1", "xxx", "xxx", "xxxxxxx")
cursor = db.cursor()
sql="""CREATE TABLE EMPLOYEE (
FIRST_NAME CHAR(20) NOT NULL,
LAST_NAME CHAR(20),
AGE INI,
SEX CHAR(1),
INCOME FLOAT )"""
cursor.execute(sql)
db.close()
问题:
/usr/bin/python2.7 /home/mfae/PycharmProjects/dbs/create.py
/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning: /home/mfae/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
warnings.warn(msg, UserWarning)
Traceback (most recent call last):
File "/home/mfae/PycharmProjects/dbs/create.py", line 14, in <module>
cursor.execute(sql)
File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line 205, in execute
File "build/bdist.linux-i686/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_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 'INI,\n SEX CHAR(1),\n INCOME FLOAT )' at line 4")
Process finished with exit code 1
进程已完成,退出代码为 1 进程已完成,退出代码为 1 进程已完成,退出代码为 1
解决方案是什么?
最佳答案
就像错误所说,你应该
将 AGE INI
更改为 AGE INT
。
关于mysql - Pycharm:MySQLdb 和数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40781720/