python—mysql数据库
发布日期:2021-05-10 10:21:32 浏览次数:18 分类:精选文章

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

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

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

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

  • ��������� (Atomicity)���������������������������������������������������������������������������������������
  • ��������� (Consistency)������������������������������������������������������
  • ��������� (Isolation)���������������������������������������������������
  • ��������� (Durability)������������������������������������������������������������������������������

��� Python ������������������������������������������������������������������������������������������������������������������ commit() ���������������������������������������������

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

  • ��������������������������������������������������������� start transaction������������������������������������������������������������������
  • ���������������������������������������������������������������commit���������������������������������������������������������������
  • ��������������������������������������������������������������������������� rollback ���������������������������

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

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

  • ������������������������ pymysql.connect() ������������������������
  • ������������������������������������������������ cursor���������������������������������������
  • ���������������������������������������������������������
  • ������������������������������������ commit() ��� rollback()���
  • ������������������������������������������������������������������������������������������������������
  • ������������������

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

    import pymysql
    config = pymysql.connect(
    host='127.0.0.1',
    port=3306,
    user='root',
    password='qwe123',
    charset='utf8'
    )
    try:
    def insert_data(id, name):
    with config.cursor() as curs:
    curs.execute('use ���������1')
    curs.execute(f"insert into ��������� values ({id}, '{name}')")
    config.commit()
    insert_data(1, '������')
    except Exception as e:
    print(f'���������������{e}')
    config.rollback()
    finally:
    config.close()
    curs.close()

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

    • ������������������������������������������������������������������������������������������������������������
    • ������������������������������������������������������������������������������������ use ������������������
    • ������������������������������������������������������������������ create table ���������
    • ��������������������� select * from ������ ���������������desc ������ ������������������
    • ���������������������������������������������������������������������������������������������������������������������
    • ������������������������������������������������������������������������������������������������������

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

    上一篇:python-redis数据库
    下一篇:python-mongoDB数据库操作

    发表评论

    最新留言

    很好
    [***.229.124.182]2025年04月17日 20时51分21秒