python pymysql cursors_Python 3 进阶 —— 使用 PyMySQL 操作 MySQL

PyMySQL 是一个纯 Python 实现的 MySQL 客户端操作库,支持事务、存储过程、批量执行等。

PyMySQL 遵循 Python 数据库 API v2.0 规范,并包含了 pure-Python MySQL 客户端库。

安装

pip install PyMySQL

创建数据库连接

import pymysql

connection = pymysql.connect(host='localhost',

port=3306,

user='root',

password='root',

db='demo',

charset='utf8')

参数列表:

参数

描述

host

数据库服务器地址,默认 localhost

user

用户名,默认为当前程序运行用户

password

登录密码,默认为空字符串

database

默认操作的数据库

port

数据库端口,默认为 3306

bind_address

当客户端有多个网络接口时,指定连接到主机的接口。参数可以是主机名或IP地址。

unix_socket

unix 套接字地址,区别于 host 连接

read_timeout

读取数据超时时间,单位秒,默认无限制

write_timeout

写入数据超时时间,单位秒,默认无限制

charset

数据库编码

sql_mode

指定默认的 SQL_MODE

read_default_file

Specifies my.cnf file to read these parameters from under the [client] section.

conv

Conversion dictionary to use instead of the default one. This is used to provide custom marshalling and unmarshaling of types.

use_unicode

Whether or not to default to unicode strings. This option defaults to true for Py

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值