美文网首页
Python 中操作 MySQL ;

Python 中操作 MySQL ;

作者: Ancestor楠 | 来源:发表于2020-02-20 21:23 被阅读0次

Python 中操作 MySQL 步骤

connection链接;cursor游标(储存执行sql语句)

以下四步是固定的

1、引入模块

import pymysql

from  pymysql  import  connect

2、创建Connection连接

# connect-连接 host-要连接的主机 port-端口 user-用户 password-密码 database-使用的数据库 charset-字符编码

conn=connect(host='localhost',port=3306,user='root',password='xxx',database='aashford',charset='utf8')

3、获得Cursor对象(返回值是游标对象)

cursor = conn.cursor()

4、关闭Cursor对象

cursor.close() #关闭游标

conn.close() #关闭连接

相关文章

网友评论

      本文标题:Python 中操作 MySQL ;

      本文链接:https://www.haomeiwen.com/subject/yzefqhtx.html