innodb table level lock 与lock table语句关系

DDL语句只申请意向级别的表锁。在lock table语句中,mysql会申请mysql级别表锁,同时innodb也会申请innodb级别表锁。前提是innodb_table_locks=1

https://www.percona.com/blog/2012/07/31/innodb-table-locks/

MySQL Table level locks and Innodb Table Levellocks are two separate beings. You almost never will run into problems withInnodb table level locks because innodb will only set intentional level locks for everythingby DDL operations.
If you’re having locking issues with Innodbchances are it is row level locks or auto increment table level lock (mostlywith MySQL 5.0 and older MySQL versions). MySQL level locks are entirelydifferent story. Explicitly locking tables on MySQL level will prevent
tablesfrom being accessed and will not show up in SHOW ENGINE INNODB STATUS. It is agood practice not to use LOCK TABLES when you’re using Innodb Tables.

http://blog.csdn.net/wanghai__/article/details/6724825

http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html

A new startup option named innodb_table_locks was added thatcauses LOCK TABLE to

also acquire InnoDB table locks.This option is enabled by default. This can cause deadlocks in applicationsthat use AUTOCOMMIT=1 and LOCK TABLES. If you application encounters deadlocksafter upgrading, you
may need to add innodb_table_locks=0 to your my.cnf file.

Beginning with MySQL 4.0.20 and 4.1.2, theMySQL LOCKTABLES operation acquires two

locks on each table if innodb_table_locks=1. (1 is the default.) In addition to a table lock

on the MySQL layer, it also acquires anInnoDB table lock. Older versions of MySQL do not

acquire InnoDB table locks. Beginning withMySQL 4.0.22 and 4.1.7, the old behavior can be

selected by setting innodb_table_locks=0.If no InnoDB table lock is acquired, LOCK

TABLES completes even if some records ofthe tables are being locked by other transactions.

All InnoDB locks held by a transaction arereleased when the transaction is committed or aborted.

Thus, it does not make much sense to invokeLOCK TABLES on InnoDB tables in AUTOCOMMIT=

1 mode, because the acquired InnoDB tablelocks would be released immediately.

? Sometimes it would be useful to lock further tables in the courseof a transaction. Unfortunately,

LOCK TABLES in MySQL performs an implicitCOMMIT and UNLOCK TABLES. An InnoDB

variant of LOCK TABLES has been plannedthat can be executed in the middle of a transaction.

Locking and Transactions

LOCK TABLES acquires two locks on eachtable if innodb_table_locks=1 (the default). In addition to a table lock on theMySQL layer, it also acquires an InnoDB table lock. Versions of MySQL before4.1.2 did not acquire InnoDB table locks; the old behavior can
be selected bysetting innodb_table_locks=0. If no InnoDB table lock is acquired, LOCK TABLEScompletes even if some records of the tables are being locked by other transactions.

In MySQL 5.6, innodb_table_locks=0 has noeffect for tables locked explicitly with LOCK TABLES ... WRITE. It does have aneffect for tables locked for read or write by LOCK TABLES ... WRITE implicitly(for example, through triggers) or by LOCK TABLES ... READ.

All InnoDB locks held by a transaction arereleased when the transaction is committed or aborted. Thus, it does not makemuch sense to invoke LOCK TABLES on InnoDB tables in autocommit=1 mode becausethe acquired InnoDB table locks would be released immediately.

You cannot lock additional tables in themiddle of a transaction because LOCK TABLES performs an implicit COMMIT andUNLOCK TABLES.

The limit of 1023 concurrent data-modifyingtransactions has been raised in MySQL 5.5 and above. The limit is now 128 *1023 concurrent transactions that generate undo records. You can remove anyworkarounds that require changing the proper structure of your
transactions,such as committing more frequently.

时间: 2024-10-11 00:02:30

innodb table level lock 与lock table语句关系的相关文章

linux mysql启动报错Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

vi /etc/my.cnf  查看日志文件路径: log-error=/var/log/mysqld.log 查看报错日志: 之前的服务器被别人拿了,所以自己买了台美国vps,根据笔记安装完启动mysql,又启动不了. 查看了错误日志 引用 090321 18:55:03 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data /usr/local/mysql/libexec/mysqld: Ta

【转】安装mysql 出现:Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

来源:http://blog.csdn.net/dapeng0112/article/details/37053407 本来初始化配置是这样的: scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql 出现了 [[email protected] mysql-5.6.14]# service mysql restart ERROR! MySQL server

mysql启动报错:Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist

mysql在首次启动的时候可能会报错:Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist 这时候可以执行脚本 mysql_install_db –user=mysql –ldata=数据存放的路径

启动mysql问题Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

启动mysql出现问题 /etc/init.d/mysqld start MySQL server PID file could not be found![FAILED] Starting MySQL......................................The server quit without updating PID file (/data/mysql/mysql_3306/data/mysql.pid).[FAILED] 查看错误日志 150619 15:57:

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

[[email protected] scripts]# ./mysql_install_db --user=mysql --basedir=/app/servers/mysql-5.5.20 --datadir=/app/servers/mysql-5.5.20/data/ 加上--datadir=/app/servers/mysql-5.5.20/data/ 问题解决!!! [ERROR] Fatal error: Can't open and lock privilege tables:

mysql安转过程中出现的问题! Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exis

net start mysql启动失败,报错信息如上,因缺少mysql这个库 所以跳过 在my.ini中添加 --skip-grant-tables 再启动mysql 然后进入mysql 倒入一个从其他机器中拷贝的mysql.sql 再把my,ini中的--skip-grant-tables注释掉 就可以启动了! mysql安转过程中出现的问题! Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn

Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

[[email protected] download]# service mysqld start Redirecting to /bin/systemctl start  mysqld.service Job for mysqld.service failed because a timeout was exceeded. See "systemctl status mysqld.service" and "journalctl -xe" for details

Mysql报错Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

安装mysql后,启动时候没有启动成功,查看了下日志报错如下:--------------------------------------------- 1   可以:初始化mysql:mysql_install_db 2   目录权限问题chown -R mysql:mysql  /var/lib/mysql [[email protected] local]# less /var/log/mysqld.log1.查看报错信息如下:[ERROR] Fatal error: Can't open

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

这个问题是由于data的目录下没有安装数据库表 解决方法: vi /etc/my.cnf 修改为正确的datadir="xxxxx"即可 然后service mysqld start service mysql start 正常启动后,会再/var/lib/mysql下面生成mysql.sock文件, 然后还报:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'