Created
October 4, 2012 05:15
-
-
Save bsodmike/3831604 to your computer and use it in GitHub Desktop.
Setup mysql database for development in Ruby!
This file contains 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' | |
@db_host = 'localhost' | |
@login_user = 'root' | |
STDOUT.sync = true | |
puts "Enter password for mysql root user:" | |
@login_pass = gets.chomp | |
puts "\nDatabase name:" | |
@db_name = gets.chomp | |
puts "\nDatabase username:" | |
@db_user = gets.chomp | |
puts "\nDatabase user password:" | |
@db_pass = gets.chomp | |
client = Mysql2::Client.new(:host => @db_host, | |
:username => @login_user, | |
:password => @login_pass) | |
client.query("CREATE DATABASE #{@db_name} CHARACTER SET utf8") | |
client.query("GRANT USAGE ON *.* TO #{@db_user}@#{@db_host} IDENTIFIED BY '#{@db_pass}'") | |
client.query("GRANT ALL PRIVILEGES ON #{@db_name}.* TO #{@db_user}@#{@db_host}") | |
client.query("FLUSH PRIVILEGES") | |
client.close |
This file contains 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 'pry' | |
@db_host = 'localhost' | |
@login_user = 'root' | |
STDOUT.sync = true | |
puts "Enter password for mysql root user:" | |
@login_pass = gets.chomp | |
puts "\nDatabase name (without 'db' suffix):" | |
@db_name = gets.chomp | |
puts "\nDatabase username:" | |
@db_user = gets.chomp | |
puts "\nDatabase user password:" | |
@db_user_pass = gets.chomp | |
@dev_db = @db_name + 'db' | |
@test_db = @db_name + 'testdb' | |
client = Mysql2::Client.new(:host => @db_host, | |
:username => @login_user, | |
:password => @login_pass) | |
client.query("CREATE DATABASE #{@dev_db} CHARACTER SET utf8") | |
client.query("CREATE DATABASE #{@test_db} CHARACTER SET utf8") | |
client.query("GRANT USAGE ON *.* TO #{@db_user}@#{@db_host} IDENTIFIED BY '#{@db_user_pass}'") | |
client.query("GRANT ALL PRIVILEGES ON #{@dev_db}.* TO #{@db_user}@#{@db_host}") | |
client.query("GRANT ALL PRIVILEGES ON #{@test_db}.* TO #{@db_user}@#{@db_host}") | |
client.query("FLUSH PRIVILEGES") | |
client.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment