LoginSignup
0
0

More than 3 years have passed since last update.

Docker の MySQL で大量レコードで遊ぶレシピ

Posted at
~/init_dummy.sql
create table users (
  id int not null auto_increment,
  name varchar(255),
  score int not null default 0,
  primary key (id)
);

delimiter //
create procedure insert_users(in x int)
begin
  declare i int default 0;
  while i < x do
    -- insert data は自由に適当にどうぞ
    insert into users (name, score) values (concat('name', i), ROUND(RAND() * 1000));
    set i = i + 1;
  end while;
end
//
delimiter ;

call insert_users(100000); -- 10万行くらい用意してみましょう

上のファイルを適当に用意しておいて。

# コンテナたてて
$ docker run -it --rm \
  --name my_container \
  -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
  -e MYSQL_DATABASE=sample_db \
  -p 3306:3306 \
  -v ~/init_dummy.sql:/docker-entrypoint-initdb.d/init_dummy.sql \
  mysql:5.7
# コンテナに入る
$ docker exec -it my_container mysql sample_db

以上で、10万行と戯れることができます。 :lemon:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0