Mysql queries the transactions being executed and how to wait for locks

Mysql queries the transactions being executed and how to wait for locks

Use navicat to test and learn:

First use set autocommit = 0; (cancel autocommit, then when the commit or rollback statement is executed, the transaction is committed or rolled back)

Open an update

Query the transactions being executed:

SELECT * FROM information_schema.INNODB_TRX 

According to the thread ID of this transaction ( trx_mysql_thread_id ):

From the above figure, we can see the corresponding mysql threads: one is 94362 (the second one is waiting for the lock) and the other is 93847 (the first update is executing without committing the transaction)

You can use the mysql command: kill thread id to kill the thread

If the thread holding the lock is not killed during this period: the second update statement prompts that the waiting time for the lock has timed out

You can also use the query mysql database:

View locked transactions

SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

View transactions waiting for locks

SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;

Query the processes that exist in the MySQL database

[sql] view plain copy

select * from information_schema.`PROCESSLIST`(show processlist;)

concept:

database , instance , session in mysql.

To establish a session in MySQL, you do not connect to a specific database, but to establish a session with the instance (that is, when executing a query on Navicat, you can query multiple databases corresponding to the port, and the database name + data table name is sufficient for the query)

Multiple instance can be created on a physical machine and the instances can be distinguished by port .

An instance can create multiple databases, that is, a session can operate multiple databases on an instance.

The jdbc protocol connects to the database: jdbc:mysql://localhost:3306/test The jdbc protocol connects to the test database under the local instance with port 3306. You do not need to add the database name when querying the data table.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Example of viewing and modifying MySQL transaction isolation level
  • How to find out uncommitted transaction information in MySQL
  • Detailed explanation of the implementation principle of ACID transaction in Mysql
  • Explanation of mysql transaction select for update and data consistency processing
  • Example of MySQL transaction processing operation implemented in Java
  • Solution to PHP+MySQL high-concurrency locked transaction processing problem
  • How to start a transaction in MySQL

<<:  Summary of Docker common commands and tips

>>:  WeChat Mini Program uses simultaneous interpretation to implement speech recognition

Recommend

Steps to set up Windows Server 2016 AD server (picture and text)

Introduction: AD is the abbreviation of Active Di...

Use pure CSS to achieve scroll shadow effect

To get straight to the point, there is a very com...

CSS to achieve horizontal lines on both sides of the middle text

1. The vertical-align property achieves the follo...

Vue-cli framework implements timer application

Technical Background This application uses the vu...

Web design experience: Make the navigation system thin

<br />When discussing with my friends, I men...

MySQL scheduled task implementation and usage examples

This article uses examples to illustrate the impl...

Vue globally introduces scss (mixin)

Table of contents 1. mixin.scss 2. Single file us...

Detailed explanation of the role of static variables in MySQL

Detailed explanation of the role of static variab...

Websocket+Vuex implements a real-time chat software

Table of contents Preface 1. The effect is as sho...

Detailed explanation of Linux DMA interface knowledge points

1. Two types of DMA mapping 1.1. Consistent DMA m...

Two methods to implement Mysql remote connection configuration

Two methods to implement Mysql remote connection ...

Detailed explanation of MySQL and Spring's autocommit

1 MySQL autocommit settings MySQL automatically c...

How to start the spring-boot project using the built-in linux system in win10

1. Install the built-in Linux subsystem of win10 ...