简体   繁体   中英

How to speed up to make save file from database

I have a mysql database. It's very huge database. When I select the data with 1M records, I should make the csv file on the disk. I make the PHP script. But It's killed by Linux. How can I make the PHP script with fast speed?

        $batches = $itemcount / 50000; 
        for ($i = 0; $i <= $batches; $i++) {

            $offset = $i * 50000;
            $sql = $sql_org . " LIMIT  $offset, 50000 ";

        $stmt = $db->prepare($sql);


            if($stmt) {
                if($stmt->execute()) {
                     $stmt->bind_result($FIRSTNAME, $LASTNAME, $PHONE....

Install mysql client and piping out the output

shell_exec('mysql -u username -p "password" --database=dbname --host=AWShostname --port=AWSport --batch 
  -e "select * from `table`" 
  | sed #s/\t/","/g;s/^/"/;s/$/"/;s/\n//g# > /path/to/yourlocalfilename.csv')

Note: exporting huge amount of data from AWS is to expensive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM