Skip to content

Instantly share code, notes, and snippets.

@stephanwehner
Last active June 14, 2018 21:24
Show Gist options
  • Save stephanwehner/6212e0563404c6723d256fb898dbbfc8 to your computer and use it in GitHub Desktop.
Save stephanwehner/6212e0563404c6723d256fb898dbbfc8 to your computer and use it in GitHub Desktop.
Alternative to rails dbconsole -- which loads much quicker
#!/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