报错
(1044, "Access denied for user 'erio'@'localhost' to database 'library'")
就是权限问题了,没什么好说的,,,换成了root //或许也可以给erio权限
SQL SERVER 有ntext类型,mysql中无,直接使用 text
插入数据时报错:
%d format: a number is required, not str
我看了一下,要插入的table 的数据类型是int,然后传送的数据类型也是int,按理来说不应该报错啊。然后去网上搜了一下https://www.douban.com/note/206462446/
,这里说只要传送的格式对了就可以,INSERT INTO 全写%S。然后修改了代码,解决了问题
另外还修改了 set NUM =%S (原来是&d)
传入以下格式的字典
book_msg{'BID': str,'BNAME': str,'AUTHOR': str,'PUBLICATION_DATE': str,'PRESS': str,'POSITION': str,'SUM': int,'CLASSIFICATION': str
}
INSERT
INTO book
VALUES(%s, %s, %s, %s, %s, %s, %s, %s)''', (
book_info['BID'],
book_info['BNAME'],
book_info['AUTHOR'],
book_info['PUBLICATION_DATE'],
book_info['PRESS'],
book_info['POSITION'],
book_info['SUM'],
book_info['SUM']
))
然后是cursor 的问题
我不知道怎么样同时拼接多条语句,比如这样会报错
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
cursor.execute('''# USE Library
# CREATE TABLE student(
# SID char(15) PRIMARY KEY,
# PASSWORD char(70),
# SNAME text,
# DEPARTMENT nchar(20),
# MAJOR nchar(20),
# MAX int
# )
# CREATE TABLE administrator(
# AID char(15) PRIMARY KEY,
# PASSWORD char(70)
# )''')
还不知道怎么解决,就只能每个事务都分开然后最后commit了。这样有些麻烦
cursor.execute('''CREATE TABLE classification(
BID char(15),
CLASSIFICATION nchar(15),
PRIMARY KEY(BID, CLASSIFICATION)
)''')
cursor.execute('''INSERT
INTO administrator
VALUES('admin', '123456')''')
conn.commit()