Is there a way to export over 10 million pieces of data from mysql-php faster?

Source: Internet
Author: User
It takes more than 10 minutes to export data using phpExcel, and the memory reports an error... is there any way to export a large amount of data faster ?... I forgot to mention that some data customers need to use it, so it takes about 10 minutes to export data in the excel format using phpExcel, and the memory reports an error...
Is there any way to make exporting large amounts of data faster?
... Forget to say that because some data customers need to use it, they must use the excel format.

Reply content:

It takes more than 10 minutes to export data using phpExcel, and the memory reports an error...
Is there any way to make exporting large amounts of data faster?
... Forget to say that because some data customers need to use it, they must use the excel format.

First, we should clarify the problem scenario:
1. this 10 million data exported is a user's function or a function in the background or in the system. If it is a user's function, PHP may be difficult to handle, because the user experience should be considered, this feature may need to be implemented using third-party services or other extensions. However, if it is not used by users, it is used by system personnel or insiders. There are many methods.
Step-by-step analysis
1. Export 10 million data records from the mysql database. 2. Export 0.1 million days of data.
First, let's take a look at the mysql database query time:
I just tested it. My 0.11 million data imports about 205 s. Everyone is different because of machine problems. But it can be clear that this time is not fast. If PHP is used, the default connection time is 30 s, and the first problem is timeout. This is a good solution
2. Use PHP to export 10 million data records. There will be a second problem with 10 million data records, with insufficient memory. Processing 10 million data records is slow
Suggestion:
1. For example, @ the miserable uncle's solution exports 10 entries in multiple batches. Because it is a SELECT statement, it does not occupy too much MYSQL resources and can query SQL statements in multiple threads.
However, this can only solve the query problem, but the query is faster. This can optimize the time of the first step, but the problem of exporting 10 pieces of data using PHP is still, because we need to export 10 million pieces of data into an excel file. To solve this problem, you can use csv, which is much faster than phpexcel,
2. If the data volume is too large or the application scenario is frequent, you can create a service.

Multiple files are exported.
For example, if you want to export 10 million data records, you can export one million data records at a time.
Multi-process processing is supported.

I guess you checked the database and got 100,000 records at a time and then exported them. This occupies a lot of memory.
You can try to retrieve 10 thousand entries by page for ten times each time. Finally, merge the exported files.

Is it not good to use mysqldump that comes with mysql?

If excel is required, you can connect to the database through odbc and export it to excel.

I have no problem exporting 500000. Remember to release the memory.

Directly operate on the database, export data from mysql, and write some desktop programs for conversion?

CSV has no pressure

In csv format. Do not use phpexcel.

Use csv. Do not use phpexcel. Reading Speed of such things is particularly slow. I have suffered a loss.

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.