Mysql+php+pdo Bulk Add Big Data

Source: Internet
Author: User
Tags uuid

1. insert into using INSERT INTO

Ini_set (' max_execution_time ', ' 0 ');//limit timeout, because the first kind of time is longer, simply set to 0 unlimited
$pdo = new PDO ("mysql:host=localhost;dbname=oradt_cloud1520", "root", "123456");

for ($i =0; $i <100000; $i + +) {

$str = Strrand (32);

EXEC-$pdo, "INSERT into Scan_card_picture (Uuid,account_id,handle_state,created_time,status,from_account, Accuracy,ifupdate) VALUES (' ". $str." ', ' a7kvzzyk2eyaxm2jivvpf0ls4m2ls00000001044 ', ' handled ', ' 2015-09-17 07:55:10 ', ' Active ', ' [email protected] ', ' 90 ', 1 ');
}

Using this method, the time is about 1 hours, the slow is very outrageous, there is no way, the use of the second.

2. Ini_set (' max_execution_time ', ' 0 ');
$pdo = new PDO ("mysql:host=localhost;dbname=oradt_cloud1520", "root", "123456");

  $sql = "INSERT into Scan_card_picture (uuid,account_id,handle_state,created_time,status,from_account,accuracy, Ifupdate) values ";

for ($i =0; $i <100000; $i + +) {
$str = Strrand (32);
$sql. = "('". $str. "', ' a7kvzzyk2eyaxm2jivvpf0ls4m2ls00000001044 ', ' handled ', ' 2015-09-17 07:55:10 ', ' active ', ' [email Protected] ', ' 90 ', 1), ";
}
$sql = substr ($sql, 0,strlen ($sql)-1);
Var_dump ($sql);
if ($pdo, exec ($sql)) {
echo "Insert success! ";
Echo $pdo-Lastinsertid ();
}

  Using this method, adding 100,000 times is a minute.  Ken can run the process will be error pdo::exec (): MySQL server has gone away; you can set global max_allowed_packet=2*1024*1024*10 in the MySQL console; (Detailed reference http://www.cnblogs.com/zlx7/p/4763207.html)

3. Online search can also use things to submit (every 10 article submitted once can, but time is not the second kind of fast), you can try it yourself.

  

Mysql+php+pdo Bulk Add Big Data

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.