Py之PyMySQL:Python库之PyMySQL的简介、安装、使用方法之详细攻略
2023-09-14 09:04:49 时间
Py之PyMySQL:Python库之PyMySQL的简介、安装、使用方法之详细攻略
目录
PyMySQL的简介
PyMySQL包包含一个纯Python MySQL客户端库。PyySQL的目标是对MySQL LDAP进行替换,并对CPython、PyPy和IrPython进行工作。
PyMySQL
Welcome to PyMySQL’s documentation!
PyMySQL的安装
pip install PyMySQL
PyMySQL的使用方法
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='localhost',
user='user',
password='passwd',
db='db',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
# Create a new record
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('webmaster@python.org', 'very-secret'))
# connection is not autocommit by default. So you must commit to save
# your changes.
connection.commit()
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('webmaster@python.org',))
result = cursor.fetchone()
print(result)
finally:
connection.close()
相关文章
- python的安装教程_Python的安装
- 通过pycharm安装python_python pycharm安装
- python怎么安装pandas库_panda 数据处理
- pycharm自带python环境吗_Python IDE环境之 新版Pycharm安装详细教程[通俗易懂]
- 如何在pycharm中安装pygame_python安装pycharm的方法
- python第三方库的安装方法有哪些_如何安装python的第三方库
- python要不要装pycharm-Python和pyCharm安装
- python语言变量命名规则有什么_Python变量命名规则(超级详细)
- Python,Anaconda,Pycharm的区别及详细安装步骤
- python实现矩阵的转置_Python实现矩阵转置的方法分析
- python中pygame怎么安_Python中pygame安装方法图文详解
- python安装不了whl文件_Python安装whl文件过程图解
- Py之dlib:Python库之dlib库的简介、安装、使用方法详细攻略
- python判断linux中文件是否存在_Python判断文件是否存在的三种方法
- Python 技巧篇-pip卸载python库实例演示,查看pip命令大全方法[通俗易懂]
- 【说站】python模块如何安装
- OpenCV-Python学习(1)—— OpenCV历史与安装
- python udp编程_Python核心编程
- lambda表达式python_Python中的Lambda表达式「建议收藏」
- Anaconda 安装python第三方库的各类方法
- python win32api sendmessage_Python win32api.SendMessage方法代码示例[通俗易懂]
- python 如何安装numpy库?
- 【python实操】软件安装进展提示进度条如何实现的?如何设置窗体拉伸?如何获取输入框内容?
- Linux系统如何运行Python脚本(linux执行python脚本)
- 安装Python时,报错 zipimport.ZipImportError: can’t decompress data; zlib not available详解编程语言
- Python简易操作MySQL入门教程(python操作mysql)
- 提升Linux环境:升级Python(linux升级python)
- 在Linux上学习Python——你的编程之路(linux学python)
- 使用Python连接SQL Server数据库(python连接sqlserver数据库)
- 如何在Linux中安装Python?(linux安装python)
- Linux系统下安装Python模块指南(linux安装python模块)
- linux下快速高效安装python工具(linux下python安装)
- netbeans7安装python插件的方法图解
- win7安装python生成随机数代码分享
- python实现2014火车票查询代码分享