Я получаю ошибки, касающиеся взаимосвязи Python 3.8.3 и MySQL 8.0

#python #mysql

#python #mysql

Вопрос:

В рамках моего школьного проекта я и мой друг создаем словарь английского языка с использованием взаимосвязи Python и MySQL. Однако первый запуск показывает эти ошибки:

 
    Traceback (most recent call last):
      File "C:UserssaxenAppDataLocalProgramsPythonPython38libsite-packagesmysqlconnectorconnection_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 OPENSchool filescsPython and mysql filesproject class 12Arvind's code.py", line 8, in <module>
        mycursor.execute("CREATE TABLE dict (word varchar(40), meaning varchar(10000)")
      File "C:UserssaxenAppDataLocalProgramsPythonPython38libsite-packagesmysqlconnectorcursor_cext.py", line 264, in execute
        result = self._cnx.cmd_query(stmt, raw=self._raw,
      File "C:UserssaxenAppDataLocalProgramsPythonPython38libsite-packagesmysqlconnectorconnection_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 вместе с необходимыми файлами, но это тоже не работает. Помощь приветствуется.

Комментарии:

1. Не могли бы вы поделиться кодом, который вы пытаетесь запустить? Похоже, это проблемы с запросом, который вы хотели бы выполнить

2. В CREATE TABLE инструкции отсутствуют закрывающие круглые скобки ( ')' ) в конце инструкции.

3. Этот код будет проще поддерживать, если вы сохраните все значения для вставки в список кортежей или списков и будете использовать mycursor.executemany .