安装 Python MySQL 驱动
发布日期:2021-05-10 08:40:33 浏览次数:20 分类:精选文章

本文共 1521 字,大约阅读时间需要 5 分钟。

������MySQL������������������������������

1. ������MySQL������

MySQL������������������������������������������������������������������������������Python���MySQL���������������������

������������������������MySQL���������������Python���

  • mysql-connector-python���������MySQL������������������Python���������

  • MySQL-python���������MySQL���C���������������Python���������

���������������������������������������������������������������������

$ easy_install mysql-connector-python$ easy_install MySQL-python

2. ������������

���mysql-connector-python���������������������������������MySQL������������������������������������

import mysql.connector
conn = mysql.connector.connect(user='root',
password='password',
database='test',
use_unicode=True)
cursor = conn.cursor()
cursor.execute('create table user (id varchar(20) primary key, name varchar(20))')
cursor.execute('insert into user (id, name) values (%s, %s)', ['1', 'Michael'])
# ������������
conn.commit()
cursor.close()
# ������������������
cursor = conn.cursor()
cursor.execute('select * from user where id = %s', ('1',))
values = cursor.fetchall()
print(values) # ��������������� [('1', 'Michael')]
cursor.close()
# ������������
conn.close()
上一篇:RabbitMQ 入门系列(5)— RabbitMQ 使用场景优缺点
下一篇:ubuntu 挂载 exfat 格式 U盘

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年04月27日 02时22分17秒