Mysql 8.0.25
I have a table named my_table and there is one row, contains id 3
CREATE TABLE my_table (
id bigint AUTO_INCREMENT PRIMARY KEY
);
INSERT INTO my_table(id) VALUES (3);
I connected to mysql with two clients (one is pycharm, one is terminal)
(in pycharm)
SET AUTOCOMMIT = 0;
SELECT @@AUTOCOMMIT; # 0
START TRANSACTION;
SELECT * FROM my_table WHERE id = 3 FOR UPDATE;
(in terminal)
SELECT * FROM my_table WHERE id = 3;
If there is a lock, I shouldn't be able to select the row.
I was able to SELECT the row
mysql> SELECT * FROM my_table WHERE id = 3;
+----+
| id |
+----+
| 3 |
+----+
1 row in set (0.00 sec)
What is the correct way to acquire a lock?
'for update' will not block the query, but you cannot modify it In terminal。