Million pieces of data is a small dish for many friends, but today I want to create a testing environment with a large amount of data, so I found out how to insert million pieces of data, I use 20 fields. For comparison, the first step is to use the mysql stored procedure.
Million pieces of data is a small dish for many friends, but today I want to create a testing environment with a large amount of data, so I found out how to insert million pieces of data, I use 20 fields. For comparison, the first step is to use the mysql stored procedure.
Million pieces of data is a small dish for many friends, but today I want to create a testing environment with a large amount of data, so I found out how to insert million pieces of data, I use 20 fields. For comparison, the first step is to use the stored procedure:
| The Code is as follows: |
|
|
Mysql> delimiter $
Mysql> set autocommit = 0 $
Mysql> create procedure test ()
Begin
Declare I decimal (10) default 0;
Dd: loop
Insert into 'million' ('categ _ id', 'categ _ fid', 'sortpath', 'address', 'P _ identifier ', 'Pro _ specification ', 'name', 'add _ date', 'picture _ url', 'thumb _ url', 'is _ display_front ', 'create _ html_time', 'hit ', 'Buy _ Sum', 'attr', 'templete _ style', 'is _ hot ', 'is _ new', 'is _ best') VALUES
(268, 2, '1970, ', 0, '1970, 0,262,268', '1970, 2342-01-09 09:55:43 ', 'upload/product/20111205153432_53211.jpg ', 'upload/product/thumb_20111205153432_53211.jpg', 1, 0, 0, 0, 0, 'admin', '0', 0, 0, 0, 0 );
Commit;
Set I = I + 1;
If I = 1000000 then leave dd;
End if;
End loop dd;
End; $
Mysql> delimiter;
Mysql> call test;
|
As a result, it took us 58 minutes to see the results. This is too time-consuming.
Mysql> call test;
Query OK, 0 rows affected (58 min 30.83 sec)
Very time-consuming.
So I found another method.
Use PHP code to generate data and then import the data:
| The Code is as follows: |
|
|
$ T = mktime ();
Set_time_limit (1000 );
$ MyFile = "e:/insert. SQL ";
$ Fhandler = ($ myFile, 'wb ');
If ($ fhandler ){
$ SQL = "268t2t'0,262,268, 't0t' 2342 't'000000' 423423 't'000000' 123123 't'000000' 23423423-01-09 09:55:43 't'upload/product/20111205153432_53211.jpg 't'upload/product/ thumb_20111205153432_53211.jpg 'tnulltnullt38t' piece 'T' t123t123t0 ";
$ I = 0;
While ($ I <1000000) // 1,000,000
{
$ I ++;
Fwrite ($ fhandler, $ SQL. "rn ");
}
Echo "written successfully, time consumed:", mktime ()-$ t;
} |
Then Import
| The Code is as follows: |
|
| Load data local INFILE 'e:/insert. SQL 'into TABLE tenmillion ('categ _ id', 'categ _ fid', 'sortpath', 'address', 'P _ identifier ', 'Pro _ specification ', 'name', 'description', 'add _ date', 'picture _ url', 'thumb _ url', 'shop _ url', 'shop _ thumb_url ', 'brand _ id', 'unit ', 'square _ meters_unit', 'market _ price', 'true _ price', 'square _ meters_price '); |
In less than one minute, 1 million of the data is quickly imported,
Note that fields are no longer separated by commas (,) and records are separated by rn. As a result, I insert 10 data records, and an average of data records can only be inserted in 1 minute.
In summary, when processing large data volumes, we 'd better use a third-party plug-in to back up data or directly back up data on the server. Sometimes it is not ideal to use the mysql tool.