Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello,

MySQL documentation says that LOCK command locks tables for a "session". I am confused that what is session??? does it mean user???

I am making a software that uses MySQL for database. I have hard coded the user name and password for MySQL connection in the software i.e. all the instances of the software will be using same user name and password for MySQL connection purposes. for example if one user is running my software on computer A and other person is using software on computer B, user name and password will be same.

My question is, if user with computer A locks table2 in database (lock tables db.table2) then whether user with computer B will be able to access table2 or not (as user name and password are same). Further, if user A closes the connection before unlocking the table2 then whether table2 will remain locked or not???



Thanks

Muhammad Inaam Munir
Posted

1 solution

MySQL implements internal locks to guarantee consistency across applications and "sessions". A session isn't well defined in the documentation, but I would guess that a session is analogous to a connection, regardless of the username/password used.

I would evaluate why you need or think you need to implement locks specifically. MySQL is designed to be concurrently used by multiple applications, the only reason to use locks is if you need to synchronize data or updates between applications, otherwise both applications can CRUD a table concurrently and maintain consistency.

Read Pgs 1002 to 1008[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900