jeudi 2 février 2017

Copying million rows of data from one database to another on laravel

Using Laravel Eloquent, i'm copying 7Million rows of data from one table on my old Mysql database and putting these rows on different tables on my new Mysql database. The problem is that it took almost one day to perform this and i need to re-perform this action for almost 80M of rows. I'm using chunk of 1000 data at a time. Is there any way to do it more efficiently?? Here my code:

   DB::connection('oldDataBase')->table('tableToCopy')->chunk(1000, function ($AllData){
        foreach ($AllData as $Data){
            DB::connection('newDataBase')->table('table1')->insert(
                [
                    column1 => $Data->columnToCopy,
                    etc..
                ]);


           DB::connection('newDataBase')->table('table2')->insert(
                [
                    column1 => $Data->columnToCopy,
                    etc..
                ]);
           DB::connection('newDataBase')->table('table3')->insert(
                [
                    column1 => $Data->columnToCopy,
                    etc..
                ]);
        }
    });



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2k5LEj2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire