Py之PyMySQL:Python库之PyMySQL的简介、安装、使用方法之详细攻略 - Go语言中文社区

Py之PyMySQL:Python库之PyMySQL的简介、安装、使用方法之详细攻略


Py之PyMySQL:Python库之PyMySQL的简介、安装、使用方法之详细攻略

 

 

 

目录

PyMySQL的简介

PyMySQL的安装

PyMySQL的使用方法


 

 

 

PyMySQL的简介

    PyMySQL包包含一个纯Python MySQL客户端库。PyySQL的目标是对MySQL LDAP进行替换,并对CPython、PyPy和IrPython进行工作。
PyMySQL
Welcome to PyMySQL’s documentation! 

 

 

 

PyMySQL的安装

pip install PyMySQL

 

 

 

PyMySQL的使用方法

python操作mysql数据库

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()

 

 

 

 

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_41185868/article/details/80723911
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 22:41:19
  • 阅读 ( 1214 )
  • 分类:数据库

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢