Flush tables with read lock and LOCK TABLES

Source: Internet
Author: User

Today, the flush tables with read lock command was used to solve Database Synchronization exceptions, so I learned about the lock table by the way.

1. FLUSH TABLES WITH READ LOCK

This command is global read lock. After the command is executed, all tables in all databases are locked and read-only. It is generally used for online database backup. At this time, the database write operations will be blocked and the read operations will proceed smoothly.

The unlock statement is also unlock tables.

2. lock tables tbl_name [AS alias] {READ [LOCAL] | [LOW_PRIORITY] WRITE}

This command is table-level locking. You can customize to lock a table. For example, lock tables test read does not affect write operations on other tables.

The unlock statement is also unlock tables.

When executing these two statements, you must note that the statements are implicitly submitted. When you exit the mysql terminal, unlock tables is implicitly executed. That is, to make the table lock take effect, you must keep the dialog.

P.S. MYSQL read lock and wirte lock


Read-lock: Other concurrent read requests are allowed, but write requests are blocked, that is, they can be read at the same time, but no write is allowed. Also called shared lock

Write-lock: exclusive is not allowed for other concurrent read and write requests ). Also called exclusive lock


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.