推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
nine9
V2EX  ›  Python

为什么 Python 对 MySQL 进行数据的插入之后需要 commit,数据库才会真的有数据?

  •  
  •   nine9 · Apr 20, 2019 · 5091 views
    This topic created in 2759 days ago, the information mentioned may be changed or developed.
    MySQL 使用的存储引擎是 InnoDB, 且 autocommit=ON,使用 python 包 MySQLdb
    6 replies  •  2019-04-20 23:52:15 +08:00
    starsky007
    starsky007
    Apr 20, 2019 via Android
    1
    开了事务?
    nine9
    nine9
    OP
    Apr 20, 2019
    2
    autocommit=ON 不是意味着自动 commit 吗?
    starsky007
    starsky007
    Apr 20, 2019 via Android
    3
    http://www.qttc.net/201208175.html

    MySQL 默认操作模式就是 autocommit 自动提交模式。这就表示除非**显式地开始一个事务**,否则每个查询都被当做一个单独的事务自动执行。
    dbit
    dbit
    Apr 20, 2019❤️1
    4
    autocommit 是按会话设置, 说不定你用的 python 执行默认的是 autocommit=false
    nine9
    nine9
    OP
    Apr 20, 2019
    5
    @dbit 是的,我一开始的思路也是这样,但是网上搜索了很多并没有找到答案,不过现在自己解决了。
    autocommit = kwargs2.pop('autocommit', False)
    rainmakeroly
    rainmakeroly
    Apr 20, 2019 via Android❤️1
    6
    conn.autocommit(True)
    SO 上说是你用的库默认 false
    可以先看下官方文档
    autocommit 是个方法
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2112 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 04:24 · PVG 12:24 · LAX 20:24 · JFK 23:24
    ♥ Do have faith in what you're doing.