Skip to content

Instantly share code, notes, and snippets.

@hachi-eiji
Created August 11, 2019 10:25
Show Gist options
  • Save hachi-eiji/0162d8110c907f2f5b6ba276a42c4d5d to your computer and use it in GitHub Desktop.
Save hachi-eiji/0162d8110c907f2f5b6ba276a42c4d5d to your computer and use it in GitHub Desktop.
require 'mysql2'
require 'parallel'
start = Time.now
puts "#{start} start"
# (1...10000).each do |i|
Parallel.each(1..10000) do |i|
client = Mysql2::Client.new(host: ENV['DB_HOST'],
username: ENV['DB_USER'],
password: ENV['DB_PASSWORD'],
database: ENV['DB_NAME']
)
client.query "drop database if exists test_#{i}"
client.query "create database if not exists test_#{i}"
client.query "drop table if exists test_#{i}.users"
client.query "create table if not exists test_#{i}.users (id int primary key,login_id varchar(100), keycode int(3), name varchar(2000), create_at datetime)"
client.query "create index idx_keycode on test_#{i}.users (keycode) "
client.close
puts "execute test_#{i} database"
end
# results = client.query('select * from test')
end_time = Time.now
puts "#{Time.now} finished. spend time #{end_time - start}sec."
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'mysql2'
gem 'parallel'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment