Can mysql shared lock and exclusive lock coexist?

start transaction;
select * from test where id = 8 for share;
update test set name = "grayvtouch" where id = 8;
select * from test where id = 8 for share;

at first I thought it was a shared lock , but as a result, I did get stuck by executing the following statement in another session:

select * from test where id = 8 for share;

this means that after the above transaction is executed (uncommitted), the lock finally added to the id = 8 record is the exclusive lock .

excuse me, is this the actual situation? Why is there such a phenomenon?

Jan.14,2022

buddy, your update has not been submitted, and the row lock on id=8 will not be released. So from the perspective of other transactions, you still hold the X lock on id=8 even though you add for share, after it.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4d93e-446cf.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4d93e-446cf.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?