Seconds speed insert million test data MySQL, provide you to play big data!

Source: Internet
Author: User
Tags mysql query

1. Use PHP code to loop the data you want to insert into a file

Random string function Getrandchar ($length) {$str = null; $strPol = " Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz "; $max = strlen ($strPol) -1;for ($i =0; $i < $length; $i + +) {$str. = $strPol [rand (0, $max)];//rand ($min, $max) generates a random integer}return $str between the Min and Max two numbers;} function Get_customers () {$t =mktime (); Set_time_limit (+); $myFile = "E:/insert.sql"; $fhandler =fopen ($myFile, ' WB ') ; if ($fhandler) {$i =0, while ($i <1000000)//1,000,000 {$firstname = $this->getrandchar (5);//put in a class using the FirstName. ' @qq. com '; $password = SHA1 ($firstname); $sql = "$firstname \t$firstname\t$email\t$password"; Note that the field data is separated by \ t $i++; Fwrite ($fhandler, $sql. " \ r \ n "); } echo "Write successful, time-consuming:", mktime ()-$t; }exit;}

  

2. Run the load data local infile in the MySQL query to read the files written to the data, you can seconds such as the database million data

LOAD DATA local INFILE ' e:/insert.sql ' into TABLE gc_customers (' FirstName ', ' LastName ', ' email ', ' password ');

  

Seconds speed insert million test data MySQL, provide you to play 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.