<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        EverySELECTfromyourPythonprogrammayacquireametadata_MySQL

        來源:懂視網 責編:小采 時間:2020-11-09 19:32:21
        文檔

        EverySELECTfromyourPythonprogrammayacquireametadata_MySQL

        EverySELECTfromyourPythonprogrammayacquireametadata_MySQL:python Metadata locking has been an exciting adventure for the last couple years in MySQL and MariaDB. Users and applications using only MyISAM tables are learning the joys of locking conflicts between transactions/connections. Users with
        推薦度:
        導讀EverySELECTfromyourPythonprogrammayacquireametadata_MySQL:python Metadata locking has been an exciting adventure for the last couple years in MySQL and MariaDB. Users and applications using only MyISAM tables are learning the joys of locking conflicts between transactions/connections. Users with

        python

        Metadata locking has been an exciting adventure for the last couple years in MySQL and MariaDB. Users and applications using only MyISAM tables are learning the joys of locking conflicts between transactions/connections. Users with InnoDB tables who either rely on global autocommit behavior or have explicitly set that globally in their configuration might be surprised to find Some users are seeing more than their fair share of these crop up in some very surprising places due to a particular, pernicious Python behavior:PEP-249 mandates that autocommit"must be initially off". Every time your Python programs/scripts connect to MySQL or MariaDB, a new transaction is started, and, crucially:by default, every time youSELECTin a Python program, your connection acquires a metadata lock.

        These locks are not released until your program ends or explicitly ends the transaction usingCOMMITorROLLBACK.

        A long-running monitoring tool or something that may connect, execute a couple simple SELECT statements, and keep its connection for some period of time, can cause havoc if you have other processes that try to executeALTER TABLEor other DDL on those tables.

        MariaDB 10.0 gives us a great plugin to inspect metadata locks, so we can see this behavior in action.

        MariaDB> create table test.t1 (id int unsigned not null auto_increment primary key) engine=myisam;Query OK, 0 rows affected (0.02 sec)MariaDB> insert into test.t1 values (),(),();Query OK, 3 rows affected (0.00 sec)Records: 3Duplicates: 0Warnings: 0
        $ cat simple.py#!/usr/bin/env pythonimport sys, osimport mysql.connectordb = mysql.connector.Connect(user='root')cursor = db.cursor()cursor.execute("SELECT 1 FROM test.t1")cursor.fetchall()cursor.close()cursor = db.cursor()cursor.execute("SELECT SLEEP(60)")cursor.fetchall()cursor.close()db.close()$ python simple.py
        MariaDB> install soname 'metadata_lock_info';Query OK, 0 rows affected (0.00 sec)MariaDB> show processlist;+----+------+-----------------+------+---------+------+------------+------------------+----------+| Id | User | Host| db | Command | Time | State| Info | Progress |+----+------+-----------------+------+---------+------+------------+------------------+----------+|3 | root | localhost | test | Query |0 | init | show processlist |0.000 || 14 | root | localhost:59875 | NULL | Query | 40 | User sleep | SELECT SLEEP(60) |0.000 |+----+------+-----------------+------+---------+------+------------+------------------+----------+2 rows in set (0.00 sec)MariaDB> select * from information_schema.metadata_lock_info;+-----------+-----------------+-----------------+---------------------+--------------+------------+| THREAD_ID | LOCK_MODE | LOCK_DURATION | LOCK_TYPE | TABLE_SCHEMA | TABLE_NAME |+-----------+-----------------+-----------------+---------------------+--------------+------------+|14 | MDL_SHARED_READ | MDL_TRANSACTION | Table metadata lock | test | t1 |+-----------+-----------------+-----------------+---------------------+--------------+------------+1 row in set (0.00 sec)

        Here's an excerpt from the general query log, to show what statements this connection has executed since it began:

        140624 17:24:4814 Connect root@localhost as anonymous on 14 Query SET NAMES 'utf8' COLLATE 'utf8_general_ci' 14 Query SET @@session.autocommit = OFF 14 Query SELECT 1 FROM test.t1 14 Query SELECT SLEEP(60)

        There we can see theSET @@session.autocommit = OFFstatement that disables autocommit. This behavior can be influenced in a few different ways, when usingMySQL Connector/Python:

        1. Set theautocommitconnection argument to "True".
        2. Modify theautocommitproperty of the connection after connecting.
        3. ExecuteSET AUTOCOMMIT=0orAUTOCOMMIT=OFFafter connecting.

        The facilities available may depend on the specific Python driver you are using. TheMySQLdbdriver, for instance, does not support anautocommitconnection argument.

        If you have Python programs that connect to MySQL or MariaDB, make sure you understand their autocommit behavior. It's a good practice, no matter the language or API you're using, to explicitly set the autocommit behavior that your program relies on.

        Good luck avoiding those metadata locks!

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        EverySELECTfromyourPythonprogrammayacquireametadata_MySQL

        EverySELECTfromyourPythonprogrammayacquireametadata_MySQL:python Metadata locking has been an exciting adventure for the last couple years in MySQL and MariaDB. Users and applications using only MyISAM tables are learning the joys of locking conflicts between transactions/connections. Users with
        推薦度:
        標簽: mysql python select
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 一级毛片免费播放男男| 亚洲韩国精品无码一区二区三区| 狼友av永久网站免费观看| 亚洲精品免费视频| 亚洲精品第一综合99久久| 日韩在线观看免费| 国产传媒在线观看视频免费观看| 亚洲av无码专区在线电影天堂| 久久久精品视频免费观看 | 精品国产亚洲男女在线线电影| 亚洲综合一区二区国产精品| 亚洲av无码专区在线电影天堂| 日本高清免费aaaaa大片视频| 久久久久久亚洲精品| 免费A级毛片无码A∨中文字幕下载| 韩国18福利视频免费观看| 亚洲av色香蕉一区二区三区| 四虎影视精品永久免费| 一级免费黄色大片| 亚洲AV永久无码精品成人| 18禁美女裸体免费网站| 亚洲综合成人婷婷五月网址| 又大又黄又粗又爽的免费视频| 一级免费黄色大片| 久久综合亚洲色HEZYO社区| 特色特黄a毛片高清免费观看| 亚洲精品乱码久久久久久| 69影院毛片免费观看视频在线 | 日本zzzzwww大片免费| 亚洲色婷婷综合开心网| 中文字幕日本人妻久久久免费| 亚洲天堂男人天堂| 在线观看免费为成年视频| 亚洲精品在线免费观看视频| 中文字幕在线免费视频| 一本色道久久88亚洲综合 | 亚洲情a成黄在线观看动漫尤物| 蜜桃视频在线观看免费网址入口| 亚洲尹人九九大色香蕉网站| 啦啦啦高清视频在线观看免费| 日韩精品免费一线在线观看|