mysql+python+pymysql的一些细节问题
报错
(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()
mysql+python+pymysql的一些细节问题的更多相关文章
- mysql python pymysql模块 基本使用
我们都是通过MySQL自带的命令行客户端工具mysql来操作数据库,那如何在python程序中操作数据库呢? 这就用到了pymysql模块,该模块本质就是一个套接字客户端软件,使用前需要事先安装 pi ...
- mysql python pymysql模块 增删改查 插入数据 介绍 commit() execute() executemany() 函数
import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' mysql_pwd = ' encoding = ...
- mysql python pymysql模块 增删改查 查询 fetchone
import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' mysql_pwd = ' encoding = ...
- mysql python pymysql模块 增删改查 查询 字典游标显示
我们看到取得结果是一个元祖,但是不知道是哪个字段的,如果字段多的时候,就比较麻烦 ''' (1, 'mike', '123') (2, 'jack', '456') ''' 用字典显示查询的结果,也可 ...
- mysql python pymysql模块 增删改查 查询 fetchmany fetchall函数
查询的fetchmany fetchall函数 import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' ...
- mysql python pymysql模块 获取插入的最后一条数据的自增ID lastrowid()方法
调用游标下的lastrowid 可以获取插入之前的表里id字段存放到哪个自增id cursor.lastrowid mysql> select * from userinfo; +----+-- ...
- Python中操作mysql的pymysql模块详解
Python中操作mysql的pymysql模块详解 前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持 ...
- 解决python pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
解决python pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query') 学习了:ht ...
- python + pymysql连接数据库报“(2003, "Can't connect to MySQL server on 'XXX数据库地址' (timed out)")”
python + pymysql连接数据库报"(2003, "Can't connect to MySQL server on 'XXX数据库地址' (timed out)&quo ...
随机推荐
- 解决ROR 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 'creat table study_record( id int(11) not null
之前一直用的好好的,突然就出现了这个错误: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual tha ...
- CentOS对接GlusterFS
存储节点部署示例环境,仅供参考 主机名 IP 系统 gfs01 10.10.10.13 CentOS 7.4.1708 gfs02 10.10.10.14 CentOS 7.4.1708 一.Glus ...
- STL_map和multimap容器
一.map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. map中key值是唯一的.集合中的元素按一定的顺 ...
- Android 8.0/9.0 wifi 自动连接评分机制
前言 Android N wifi auto connect流程分析 Android N selectQualifiedNetwork分析 Wifi自动连接时的评分机制 今天了解了一下Wifi自动连接 ...
- .net core 不同地区时间相互转换
.net core 不同地区时间相互转换 //韩国时间转换成当前时间 //value=需要转换的时间 //Korea Standard Tim 韩国时间 //China Standard Time 中 ...
- charles安装使用乱码连手机等问题解决方案
捣鼓半天终于安装好了,给大家分享下我的过程 1.安装, 正常网上安装即可,我安装了个有汉化包的,,推荐链接 安装方法下载破解版,安装即可 安装包地址:https://pan.baidu.com/s/1 ...
- Update Node Using a Package Manager nodesource
How to Update Node.js to Latest Version (Linux, Ubuntu, OSX, Others) - HostingAdvice.com https://www ...
- How Interfaces Work in Go
research!rsc: Go Data Structures: Interfaces https://research.swtch.com/interfaces How Interfaces Wo ...
- WPF mvvm 验证,耗时两天的解决方案
常用类 类名 介绍 ValidationRule 所有自定义验证规则的基类.提供了让用户定义验证规则的入口. ExceptionValidation 表示一个规则,该规则检查在绑定源属性更新过程中引发 ...
- Golang 版的ssh爆破小工具
源码如下: package main import ( "bufio" "flag" "fmt" "golang.org/x/cr ...