views:

27

answers:

1

I have a MySQL DB which manages users’ accounts data. Each user can only query he’s own data. I have a script that on initial login gets the user data and inserts it to the DB. I scheduled a cron process which updates all users’ data every 4 hours.

Here are my questions regarding it:

(1) - Do I need to implement some kind of lock mechanism on the initial login script? This script can be executed by large number of users simultaneously - but every user has a dedicated place in the DB so it does not affect other DB rows.

(2) - Same question on the cron process, should I handle this scenario: While the cron process updates user i data, user i tries to fetch his data from the DB. I mean does MySQL already support and handles this scenario?

Any help would be appreciated.

Thanks.

A: 

No, you don't need to lock the database, MySQL engine handles this task for you. If you would make your database engine by yourself, you would have to be sure, that nothing will get in the way or conflict with data update, but since you are running such a smart thing as MySQL, you don't need to worry about it.

While data is updated, all queries will stand in line, until update finishes.

Silver Light