Home > database >  [for] use python link mysql times wrong You have an error in your SQL syntax; Check the manual tha
[for] use python link mysql times wrong You have an error in your SQL syntax; Check the manual tha

Time:09-30

Error is as follows:
Pymysql. Err. 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 'AUTO_INCERMENT, \ n BOOK VARCHAR (255), \ n PRIMARY KEY (' id')=INNOD '\ n) ENGINE at line 2 ")
SQL statements:
Create_sql="'
The CREATE TABLE python (
Id INT (11) the NOT NULL AUTO_INCERMENT,
BOOK a VARCHAR (255),
PRIMARY KEY (' id ')
) ENGINE=INNODB DEFAULT CHARSET=utf8
' ' '

CodePudding user response:

Since the increase is AUTO_INCREMENT
Not AUTO_INCERMENT

Words are spelt wrong.

CodePudding user response:

reference 1st floor flysky2015 response:
since the increase is AUTO_INCREMENT
Not AUTO_INCERMENT

Words are spelt wrong.
thank you, have to correct, but create a form after execution success, but it was empty, please have a look, again much code is as follows:
The import requests
The from bs4 import BeautifulSoup
The import pymysql
Def gethtmltext (url) :
Try:
R=requests. Get (url, timeout=100)
R.r aise_for_status ()
R.e ncoding=of state Richard armitage pparent_encoding
Return r.t ext
Except:
Return ""

Def getpages (HTML) :
Try:
Name=[]
Soup=BeautifulSoup (HTML, '. The HTML parser)
Div_list=soup. Find_all (' div ', attrs={' class ':' title '})
For I in div:
Cont=i.f ind_all (' a ')
Na_list=name. Append (cont. String)
Except:
Return ""
Def mysql_conn () :
The db=pymysql. Connect (host="localhost", user="root",
Password="123456", the db="doubandushu port=3306)
Return the db
Def create_table () :
Create_sql="'
The CREATE TABLE HHH (
Id INT (11) the NOT NULL AUTO_INCREMENT,
BOOK a VARCHAR (255),
PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8
"'
The db=mysql_conn ()
With the db:
Cursor=the cursor ()

Cursor. The execute (create_sql)
MIT ()
db.comDef insert () :
SQL="insert into HHH (BOOK) value (% s) '
The db=mysql_conn ()
With the db (a) :
Cursor=the cursor ()
Try:
Cursor. The execute (SQL, (na_list. String))
MIT ()
cursor.connection.comExcept BaseException as e:
Print (" mistake here & gt;>" , e, & lt;" MIT ()
db.comIf __name__=="__main__ ':
For I in range (10) :

Url="https://book.douban.com/subject_search? Search_text=python& The cat=1001 & amp; Start=% s "% (I * 15)
HTML=gethtmltext (url)
Create_table ()
For I in getpages (HTML) :
Insert (I)
Print (" over ")
  • Related