[MySQLFAQ] series-how to reconcile two table names

Source: Internet
Author: User
Tags mysql manual
A student asked me, in a scenario similar to pt-osc, how can we ensure that the two table names are correct? The analysis estimated that other students laughed. Isn't table name correct easy? RENAME each other. However, what we want is to complete table name reconciliation at the same time. If it is a successive pair, some data may fail to be written. What should we do?

A student asked me, in a scenario similar to pt-osc, how can we ensure that the two table names are correct? The analysis estimated that other students laughed. Isn't table name correct easy? RENAME each other. However, what we want is to complete table name reconciliation at the same time. If it is a successive pair, some data may fail to be written. What should we do?

A student asked me, in a scenario similar to pt-osc, how can we ensure that the two table names are correct? The analysis estimated that other students laughed. Isn't table name correct easy? RENAME each other.

However, what we want is to complete table name reconciliation at the same time. If it is a successive pair, some data may fail to be written. What should we do?

In fact, it is not difficult to find a method from the MySQL manual, that is: Lock two tables at the same time, do not allow writing, and then tune the table name.

We usually only lock one table, So how should we lock two tables at the same time? The following method can be used:

Lock tables t1 WRITE, t2 WRITE; alter table t1 rename to t3; alter table t2 rename to t1; alter table t3 rename to t2; unlock tables;

As you can see, it is actually very simple. You can add a table-level write lock to the two tables at the same time, and then rename the table using the ALTER syntax.

There are a lot of nonsense. Thank you for your patience :)

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.