Mysql2::Error 用户 'root'@'localhost' 的访问被拒绝(使用密码:YES)
Mysql2::Error Access denied for user 'root'@'localhost' (using password: YES)
我想要 运行 耙子 db:migrate,但迁移已中止,我看到此错误:
rake aborted!
Mysql2::Error: Access denied for user 'root'@'localhost' (using password: YES)
/home/marketa/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `connect'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `initialize'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:87:in `connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:913:in `initialize'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `new'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `up'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:798:in `migrate'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/home/marketa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/home/marketa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
如果我 运行 服务器我会看到这个错误页面:
Mysql2::Error
Access denied for user 'root'@'localhost' (using password: YES)
Extracted source (around line #70):
socket = socket.to_s unless socket.nil?
connect user, pass, host, port, database, socket, flags #70line is this
end
def self.default_query_options
我的 database.yml 文件如下所示:
default: &default
adapter: mysql2
pool: 5
timeout: 5000
host: localhost
username: root
password: hazzy93
development:
<<: *default
database: db/dev.mysql2
test:
<<: *default
database: db/test.mysql2
production:
<<: *default
database: db/production.mysql2
您需要更正您的 database.yml
它应该是这样的:
default: &default
adapter: mysql2
host: 127.0.0.1
port: 3306
username: root
password: hazzy93
development:
<<: *default
database: development
test:
<<: *default
database: test
production:
<<: *default
database: production
您使用了 sqlite3 的语法
试试这个
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: development
pool: 5
username: root
password: hazzy93
host: localhost
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: test
pool: 5
username: root
password: hazzy93
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: production
pool: 5
username: root
password: hazzy93
host: localhost
我想要 运行 耙子 db:migrate,但迁移已中止,我看到此错误:
rake aborted!
Mysql2::Error: Access denied for user 'root'@'localhost' (using password: YES)
/home/marketa/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `connect'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `initialize'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:87:in `connection'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:913:in `initialize'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `new'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `up'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:798:in `migrate'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/home/marketa/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/home/marketa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/home/marketa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
如果我 运行 服务器我会看到这个错误页面:
Mysql2::Error
Access denied for user 'root'@'localhost' (using password: YES)
Extracted source (around line #70):
socket = socket.to_s unless socket.nil?
connect user, pass, host, port, database, socket, flags #70line is this
end
def self.default_query_options
我的 database.yml 文件如下所示:
default: &default
adapter: mysql2
pool: 5
timeout: 5000
host: localhost
username: root
password: hazzy93
development:
<<: *default
database: db/dev.mysql2
test:
<<: *default
database: db/test.mysql2
production:
<<: *default
database: db/production.mysql2
您需要更正您的 database.yml 它应该是这样的:
default: &default
adapter: mysql2
host: 127.0.0.1
port: 3306
username: root
password: hazzy93
development:
<<: *default
database: development
test:
<<: *default
database: test
production:
<<: *default
database: production
您使用了 sqlite3 的语法
试试这个
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: development
pool: 5
username: root
password: hazzy93
host: localhost
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: test
pool: 5
username: root
password: hazzy93
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: production
pool: 5
username: root
password: hazzy93
host: localhost