Php Script to check MySQL TABLE LOCK status

一曲冷凌霜 提交于 2020-01-15 05:47:07

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/4553860/php-script-to-check-mysql-table-lock-status

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!