A tool for analyzing metadata locks in MySQL databases.
- Python 3.9+
- Poetry
- Running MySQL server
- Clone the repository
- Install dependencies:
poetry install - Copy
.env.exampleto.envand fill in your database connection details. The script will prompt for the password if it is not available in the environment variables.
Run DDL query during collection:
poetry run python main.py --mode collect --ddl "CREATE TABLE test_table (id INT PRIMARY KEY, val VARCHAR(255))"To collect locks without running any queries, omit the --ddl argument:
poetry run python main.py --mode collect
Run a predefined scenario with multiple queries:
poetry run python main.py --mode scenario --query-types T1_insert T2_alter T3_insert --with-parent--mode scenario: Run in scenario mode.--query-types: Exactly three query types must be provided in the following order:- First query type: T1 (INSERT, UPDATE, or SELECT)
- Second query type: T2 (CREATE or ALTER)
- Third query type: T3 (INSERT, UPDATE, or SELECT)
--with-parent: Optional flag to set up the database with a parent table.
- T1_insert: Insert a record into test_table
- T1_update: Update a record in test_table
- T1_select: Select a record from test_table
- T2_create: Create a child_table with a foreign key to test_table
- T2_alter: Add a column to test_table
- T3_insert: Insert another record into test_table
- T3_update: Update another record in test_table
- T3_select: Select another record from test_table
poetry run python main.py --mode scenario --query-types T1_insert T2_alter T3_insert --with-parent
This command will:
- Start a transaction and insert a record into test_table (T1)
- Add a column to test_table (T2)
- Start a transaction and insert another record into test_table (T3)
- Roll back the transaction started in step 1
The --with-parent flag will set up the database with a parent table.
Ensure that performance_schema is enabled in your MySQL server. On some MySQL versions you may also need to enable metadata lock instrumentation. Check the MySQL documentation for your version for more information.