I have a scheduling table which I need to lock then read from. I am currently trying to do this:
LOCK TABLES db.schedule AS j_read READ;
SELECT * FROM db.schedule as j_read;
UNLOCK TABLES;
When I run this I get the error:
Error Code: 1100. Table 'j_read' was not locked with LOCK TABLES
I've gone over the mysql table locks documentation mysql docs but i cant figure our why this is not working for me. if i don't alias anything it works like this
LOCK TABLES db.schedule READ;
SELECT * FROM db.schedule;
UNLOCK TABLES;
Any ideas why this is not working or how to do this properly?
I found the way to make this work. Need to obtain a lock for both the alias name and the table itself
LOCK TABLES db.schedule READ,db.schedule AS j_read READ;
SELECT * FROM db.schedule as j_read;
UNLOCK TABLES;
Look at this chunk of documentation, you still need to select from table but reference your lock alias. You're looking for last line.
mysql> LOCK TABLE t AS myalias READ;
mysql> SELECT * FROM t;
ERROR 1100: Table 't' was not locked with LOCK TABLES
mysql> SELECT * FROM t AS myalias;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With