特拉维斯坚持“Mysql2 ::错误:访问被拒绝用户'root'@'localhost'`

时间:2017-03-22 20:58:18

标签: ruby-on-rails ruby travis-ci

我正在尝试为我的RoR应用程序设置Travis配置,但我无法从MySQL数据库的访问点传递。这是我的.travis内容:

language: ruby

rvm:
  - 2.4.0

cache: bundler

sudo: required

env:
  - RAILS_ENV=test

matrix:
  fast_finish: true

services:
  - mysql

addons:
  apt:
    packages:
      - imagemagick libmagickwand-dev

before_install:
  - bash .travis.install-mysql-5.7
  - gem update --system 2.6.11
  - gem update bundler

before_script:
  - cp .travis.database.yml config/database.yml

script:
  - RAILS_ENV=test bundle exec rake db:create
  - RAILS_ENV=test bundle exec rake db:migrate

在我的.travis.database.yml我已经按the book完成了所有事情:

default: &default
  adapter: mysql2
  encoding: utf8
  username: root

development:
  <<: *default
  database: site_development

test:
  <<: *default
  database: site_test

production:
  <<: *default
  database: site_production
  username: site
  password: <%= ENV['SITE_DATABASE_PASSWORD'] %>

这是特拉维斯的输出:

$ cp .travis.database.yml config/database.yml

$ RAILS_ENV=test bundle exec rake db:create
#<Mysql2::Error: Access denied for user 'root'@'localhost'>
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "username"=>"root", "database"=>"site_test"}, {:charset=>"utf8"}
(If you set the charset manually, make sure you have a matching collation)
Created database 'site_test'

The command "RAILS_ENV=test bundle exec rake db:create" exited with 0.
$ RAILS_ENV=test bundle exec rake db:migrate
rake aborted!
Mysql2::Error: Access denied for user 'root'@'localhost'

问题:

  1. travis或我的配置出了什么问题?

2 个答案:

答案 0 :(得分:1)

为了它的价值,我忘记重置新安装的MySQL 5.7的用户名&amp;密码,从here注意到。

答案 1 :(得分:0)

mysql的root用户密码是什么?

将其添加到

test:
  <<: *default
  database: site_test
  password: ROOT_PASSWORD_GOES_HERE