MySQL problem: Alter causes slow speed

Source: Internet
Author: User

1. How to execute in parallel.

There is a table with a very large data volume in the database. When alter is performed on this table, the table is read-only at this time. Because of the large data volume, alter takes a long time, if there is an insert or update operation at this time, is there any way to perform the insert or update operation during this period?

MySQL can be inserted and updated when it is alter, but the operation will be delayed. Here is my reference to the MySQL Official Website:
* "During the alter table operation, the original table will be temporarily copied, changed on the copy, deleted from the original table, and renamed. When you execute alter table, other users can read the original table, but the update and modification operations on the table will be delayed until the new table is generated. After a new table is generated, the update and modification information is automatically transferred to the new table.

Note: If you use an option other than rename when executing alter table, MySQL creates a temporary table. MySQL performs this operation even if the data does not need to be copied (for example, when you change the column name. For MyISAM tables, you can set the myisam_sort_buffer_size system variable to a high value to speed up index re-creation (this operation is the slowest part of the change process.

If you use alter table tbl_name Rename to new_tbl_name without any other options, MySQL only renames the file corresponding to table tbl_name. You do not need to create a temporary table. (You can also use the rename table statement to rename the table ." *

Therefore, we can see that MySQL copies the table structure during alter, so I suggest you save time:
1. Create table_new and remove two additional fields + Add 5 fields
2. insert into table_new select * from table: Copy all data to the new table structure.
3. Drop table; rename table_new to table; Delete the table and change the new table name to the original table name.

Of course, when the alter of a large table is used, I suggest you handle it when few users access it (for example, in the early morning)

From: http://www.dewen.org/q/3956

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.