简体   繁体   中英

PHP MySQL "Select" then "Insert" Large Data

what is the best way to Select then Insert large data into the Database (InnoDB Engine)?

I have got more than 60000 rows need to be inserted from another table without LIMIT the result.

Is there a way to prevent my server memory being consumed too much or speed up the query? Could I split the query with let say LIMIT 5000 until its done copying all the data?

this is example query:

$query = 'SELECT * FROM orig_table WHERE user_id = 1 AND sent = 0'; // more than 60000 rows

if ( $query ) {
  foreach ( $query as $row ) {
     'INSERT INTO copy_table VALUE()';    
  }   
}

Maybe just execute in in one query

insert into copytable (column1,column2)
SELECT column1,column2 FROM orig_table WHERE user_id = 1 AND sent = 0

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