开发者

Php Script to check MySQL TABLE LOCK status

开发者 https://www.devze.com 2023-02-01 09:01 出处:网络
I use mysqldump for MySQL Backup. mysqldump --lock-tables.... The DB is about 2GB, hence mysqldump takes a long time.

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 backe开发者_StackOverflowd-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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消