Created
August 11, 2019 10:25
-
-
Save hachi-eiji/0162d8110c907f2f5b6ba276a42c4d5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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