[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 858
  • Last Modified:

Bulk load dummy test data into mysql

Hi,

Im doing some testing and would like to load our MySQL database with 100,000 rows.
I assume il need to write a script to do this.
Does anyone know of any examples on how i can do this?

Thanks
Pete
0
Jonesey007
Asked:
Jonesey007
2 Solutions
 
K VDatabase ConsultantCommented:
If you have sample data ready, you may use LOAD DATA command.
LOAD DATA INFILE 'data.txt' INTO TABLE DATABASENAME.TABLENAME;
Ref: http://dev.mysql.com/doc/refman/5.1/en/load-data.html

OR

Code snippet Ref: http://forums.devshed.com/perl-programming-6/mysql-dummy-data-script-25993.html

#!/usr/bin/perl
use strict;
 
#Connect stuff up here
 
my $insert_check=$dbh->prepare('insert into testtable(col1,col2,col3,col4) values (?,?,?,?)')
     or die("Couldn't prepare test insert".$dbh->errstr());
 
my @array=( 'a'..'z' );
 
#calling array in scalar context yields the number of elements in the array
my $length=@array;
 
foreach(1..1000000){
    my $col2=int(rand(10000));
    my $col3=int(rand(100));
    my $col4;
    $col4 .= @array[int(rand($length))-1] foreach(1..int(rand(20)));
    $insert_check->execute($_,$col2,$col3,$col4)
        or die("Couldn't do insert!!".$dbh->errstr());
}
 
$insert_check->finish();
$dbh->disconnect();

Open in new window

0
 
tcs224694Commented:
Hi,

If u have the csv files ,u can do it via a phpmyadmin...

Go to phpmyadmin
click import
browse for the csv file
and select ,(comma) for terminated by
Then go.

Before that u need to create a structure of the table there in the database...

*****LOAD DATA ******command is the efficient one and for beginners phpmyadmin gui is easy.
0
 
alex_pavenCommented:
Or, if you can afford to spend some money, you could use this (their software is pretty high quality).
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now