Sanjay
Sanjay

Reputation: 47

Php Script to check MySQL TABLE LOCK status

I use mysqldump for MySQL Backup.

mysqldump --lock-tables....

The DB is about 2GB, hence mysqldump takes a long time. If anyone tries to access the DB during backup, I would like to flash a message saying "the DB is being backed-up, please return back after 10 minutes"

My questions is using PHP script, how can I check if mysql table is locked or not.

Thank you in advance.

Best regards, Sanjay

Upvotes: 2

Views: 2513

Answers (2)

ajreal
ajreal

Reputation: 47321

Prefer method will be setup replication,
and mysqldump on the slave instead on master (assuming only master is serving requests)

So, you never experiencing downtime

Upvotes: 2

SubniC
SubniC

Reputation: 10337

If you have both read/write lock you can write a php script that try to access/write in a table, if it is locked the MySQL server will rise an error and you will be able to evaluate the code and send a message if the error is because the tables are locked.

HTH!

EDIT: You can take a look of the MySQL GET_LOCK function

Upvotes: 1

Related Questions