Skip to content

Instantly share code, notes, and snippets.

@lukmdo
Created January 25, 2010 12:41
Show Gist options
  • Save lukmdo/285832 to your computer and use it in GitHub Desktop.
Save lukmdo/285832 to your computer and use it in GitHub Desktop.
MySQL generate data
# Create Fixed row_format table (better indexes than for Dynamic)
mysql> CREATE TABLE test_tab (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
id_2 int(11) unsigned NOT NULL,
id_3 int(11) unsigned NOT NULL,
name char(10) NOT NULL,
c_date date NOT NULL,
mtime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ENGINE=MyISAM
# procedure to populate 8_000_000 semi-random rows
mysql> delimiter //
mysql> CREATE PROCEDURE load_test_tab()
begin
declare v int default 0;
while v < 8000000
do
insert into
test_tab(id_2,id_3, name, c_date)
values (ceil(mod(rand()*1000,1000)), ceil(mod(rand()*10000,10000)), 'testing', adddate('1995-01-01',(rand(v)*36520) mod 3652));
set v = v + 1;
end while;
end
//
mysql> delimiter ;
mysql> call load_test_tab();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment