推荐学习书目
› 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 · 4925 views
    This topic created in 2718 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
        1
    starsky007  
       Apr 20, 2019 via Android
    开了事务?
    nine9
        2
    nine9  
    OP
       Apr 20, 2019
    autocommit=ON 不是意味着自动 commit 吗?
    starsky007
        3
    starsky007  
       Apr 20, 2019 via Android
    http://www.qttc.net/201208175.html

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