首页 > 解决方案 > 我收到有关 Python 3.8.3 和 MySQL 8.0 互连的错误

问题描述

作为我学校项目的一部分,我和我的朋友正在制作一本具有 Python 和 MySQL 互连性的英语词典。但是第一次运行显示这些错误:


    Traceback (most recent call last):
      File "C:\Users\saxen\AppData\Local\Programs\Python\Python38\lib\site-packages\mysql\connector\connection_cext.py", line 487, in cmd_query
        self._cmysql.query(query,
    _mysql_connector.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 '' at line 1
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "D:\DO NOT OPEN\School files\cs\Python and mysql files\project class 12\Arvind's code.py", line 8, in <module>
        mycursor.execute("CREATE TABLE dict (word varchar(40), meaning varchar(10000)")
      File "C:\Users\saxen\AppData\Local\Programs\Python\Python38\lib\site-packages\mysql\connector\cursor_cext.py", line 264, in execute
        result = self._cnx.cmd_query(stmt, raw=self._raw,
      File "C:\Users\saxen\AppData\Local\Programs\Python\Python38\lib\site-packages\mysql\connector\connection_cext.py", line 491, in cmd_query
        raise errors.get_mysql_exception(exc.errno, msg=exc.msg,
    mysql.connector.errors.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 '' at line 1

这是源代码:

import mysql.connector
con=mysql.connector.connect(host='localhost',user='root',passwd='root')
mycursor=con.cursor()
mycursor.execute("DROP DATABASE IF EXISTS eng")
mycursor.execute("CREATE DATABASE eng")
mycursor.execute("USE eng")
mycursor.execute("DROP TABLE IF EXISTS dict")
mycursor.execute("CREATE TABLE dict (word varchar(40), meaning varchar(10000)")
mycursor.execute("INSERT INTO dict(word, meaning) values('Abide', 'Accept or Obey a rule or decision')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Abominate', 'To detest, dislike strongly')")
mycursor.execute("INSERT INTO dict(word, meaning) values('babble', 'to utter sounds or words imperfectly, indistinctly, or without meaning')")
mycursor.execute("INSERT INTO dict(word, meaning) values('banter', 'playful teasing')")
mycursor.execute("INSERT INTO dict(word, meaning) values('concordant', 'In agreement')")
mycursor.execute("INSERT INTO dict(word, meaning) values('concour', 'agree,happen at the same time')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Dearth', 'Scarcity or lack')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Deft', 'Quick and skilful')")
mycursor.execute("INSERT INTO dict(word, meaning) values('earnest', 'Very serious, sincere intent')")
mycursor.execute("INSERT INTO dict(word, meaning) values('eminence', 'The quality of being distinguished and respected, an important person')")
mycursor.execute("INSERT INTO dict(word, meaning) values('fallacy', 'A mistaken belief, unsound reasoning, misleading')")
mycursor.execute("INSERT INTO dict(word, meaning) values('feasible', 'Possible, able to be done')")
mycursor.execute("INSERT INTO dict(word, meaning) values('gambit', 'An action or remark intended to gain an advantage')")
mycursor.execute("INSERT INTO dict(word, meaning) values('gambit', 'The origin of something')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Hallucinate', 'See something which is not actually present')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Humility', 'The quality of being humble')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Immure', 'To shut oneself in a place alone, confine, imprison')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Imperil', 'To put in danger, endanger, pose a threat')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Jest', 'Joke, verb-speak in a joking way')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Jubilant', 'Happy and triumphant')")
mycursor.execute("INSERT INTO dict(word, meaning) values('kiosk', 'A booth from which newspapers, tickets etc are sold')")
mycursor.execute("INSERT INTO dict(word, meaning) values('knave', 'A dishonest man')")
mycursor.execute("INSERT INTO dict(word, meaning) values('lacuna', 'A gap or a missing portion')")
mycursor.execute("INSERT INTO dict(word, meaning) values('lapel', 'A flap folded back on each side of a coat')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Mandarin', 'A powerful official')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Magnitude', 'eat size or importance, size')")
mycursor.execute("INSERT INTO dict(word, meaning) values('nepotism', 'favoritism showed to relatives or friends')")
mycursor.execute("INSERT INTO dict(word, meaning) values('nocturnal', 'Done or active ate night')")
mycursor.execute("INSERT INTO dict(word, meaning) values('oblivious', 'Unaware')")
mycursor.execute("INSERT INTO dict(word, meaning) values('omen', 'An event seen as a sign of future good or bad luck')")
mycursor.execute("INSERT INTO dict(word, meaning) values('panacea', 'A solution or remedy for all difficulties or diseases')")
mycursor.execute("INSERT INTO dict(word, meaning) values('pariah', 'An outcast')")
mycursor.execute("INSERT INTO dict(word, meaning) values('quaver', 'To shake or tremble')")
mycursor.execute("INSERT INTO dict(word, meaning) values('quest', 'A long search')")
mycursor.execute("INSERT INTO dict(word, meaning) values('rampage', 'Rush around in a wild violent way')")
mycursor.execute("INSERT INTO dict(word, meaning) values('rampshackle', 'In a very bad condition')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Sanitize', 'Make hygienic, make something unpleasant seem more acceptable')")
mycursor.execute("INSERT INTO dict(word, meaning) values('Syntax', 'The arrangement of words and phrases to form sentences')")
mycursor.execute("INSERT INTO dict(word, meaning) values('tactile', 'Of having, or perceived by the sense of touch')")
mycursor.execute("INSERT INTO dict(word, meaning) values('tensile', 'Of tension, able to be stretched')")
mycursor.execute("INSERT INTO dict(word, meaning) values('unanimous', 'Fully in agreement, agreed by everyone involved')")
mycursor.execute("INSERT INTO dict(word, meaning) values('unearth', 'Discover by searching')")
mycursor.execute("INSERT INTO dict(word, meaning) values('valiant', 'Brave, noble')")
mycursor.execute("INSERT INTO dict(word, meaning) values('vantage', 'A position giving a good view')")
mycursor.execute("INSERT INTO dict(word, meaning) values('wanting', 'Lacking, absent')")
mycursor.execute("INSERT INTO dict(word, meaning) values('waltz', 'Move or act casually')")
mycursor.execute("INSERT INTO dict(word, meaning) values('xenophoia', 'dislike or fear from people from other countries')")
mycursor.execute("INSERT INTO dict(word, meaning) values('xeric', 'containing little moisture; very dry')")
mycursor.execute("INSERT INTO dict(word, meaning) values('yore', 'Long ago')")
mycursor.execute("INSERT INTO dict(word, meaning) values('yelp', 'A short sharp cry')")
mycursor.execute("INSERT INTO dict(word, meaning) values('zilch', 'nothing')")
mycursor.execute("INSERT INTO dict(word, meaning) values('zenith', 'The highest point')")
con.commit()
con.close()

我已经尝试过多次重新安装 MySQL 和 Python 以及所需的文件,但这也不起作用。帮助表示赞赏。

标签: pythonmysql

解决方案


推荐阅读