MySQL 20 million data optimization & migration

Source: Internet
Author: User

A data table with a 2000W record recently needs to be optimized and migrated. 2000W data is awkward for MySQL, because it is very fast to create indexes reasonably, and how to optimize speed is not much improved. However, these data have a large number of redundant fields and error messages, it is very inconvenient to do statistics and analysis. So I need to create a new table, the data in the old table is taken out to optimize and put back the new table;

I. Clear redundant data, optimize the field structure

In 2000W data, we anticipate the fields that can be used as query criteria. So this part of the data to create a separate new field, for the rule of the data reasonable change the field structure, such as ID is varchar (18). For unimportant data we have a field with text structure after merging.

For some related data we need to calculate, common such as identity card can get accurate gender, birthplace, birthday, age.

Two. Data migration

We take an old piece of data out of the database, get the new data we want (Tengyun technology ty300.com), and finally insert the new data into the new table. However, the following issues were encountered when acquiring new data.

1. The amount of data is too large to get at once (2000W data thrown into memory pretty scary);

We can get it in batches via the MySQL limit syntax. For example, each time you get the 50000,sql statement:

SELECT * FROM table_name limit 15000000,50000;

This method can solve the problem of too much data, but as the first parameter of limit becomes bigger and larger, the query speed will be very slow (this SQL execution will take 35 seconds). Time is life, so we start to optimize the SQL statement, and then the optimization becomes the following:

Manuscripts: Diligent Learning qkxue.net

Full version of MySQL 20 million data Optimization & Migration Introduction

MySQL 20 million data optimization & migration

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.