diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2010-08-24 12:33:11 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-08-25 18:06:55 +0200 |
commit | 1fbb0684d267ca61e9409206c9939d0aeab609c9 (patch) | |
tree | c6818fb36f960cd89901bafac56f873263f72f56 | |
parent | ffdda4ddfb76fec92faea714f03a37baf75351ef (diff) | |
download | rails-1fbb0684d267ca61e9409206c9939d0aeab609c9.tar.gz rails-1fbb0684d267ca61e9409206c9939d0aeab609c9.tar.bz2 rails-1fbb0684d267ca61e9409206c9939d0aeab609c9.zip |
Catch mysql2 access denied errors in rake db:create [#5432 state:resolved]
Signed-off-by: Xavier Noria <fxn@hashref.com>
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index ae605d3e7a..b46c4b59a2 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -61,12 +61,14 @@ namespace :db do @charset = ENV['CHARSET'] || 'utf8' @collation = ENV['COLLATION'] || 'utf8_unicode_ci' creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)} + error_class = config['adapter'] == 'mysql2' ? Mysql2::Error : Mysql::Error + access_denied_error = 1045 begin ActiveRecord::Base.establish_connection(config.merge('database' => nil)) ActiveRecord::Base.connection.create_database(config['database'], creation_options) ActiveRecord::Base.establish_connection(config) - rescue Mysql::Error => sqlerr - if sqlerr.errno == Mysql::Error::ER_ACCESS_DENIED_ERROR + rescue error_class => sqlerr + if sqlerr.errno == access_denied_error print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>" root_password = $stdin.gets.strip grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \ |