Last active
June 14, 2018 21:24
-
-
Save stephanwehner/6212e0563404c6723d256fb898dbbfc8 to your computer and use it in GitHub Desktop.
Alternative to rails dbconsole -- which loads much quicker
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
#!/usr/bin/ruby | |
# Instead of rails dbconsole. This loads a lot quicker, since it doesn't load all of rails. | |
# Place user/password in ~/.my.cnf as | |
# [client] | |
# user=whathaveyou | |
# password=whathaveyoupwd | |
require 'erb' | |
require 'yaml' | |
hash = YAML.load(ERB.new(IO.read('config/database.yml')).result) | |
env = ENV['RAILS_ENV'] || 'development' | |
config = hash[env] | |
db = config['database'] | |
$stderr.puts "Using database from ENV['RAILS_ENV'] as '#{env}': #{db.inspect}" | |
system('mysql', '-S', config['socket'], '-u', config['username'], db) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment