rails启用mysql数据库migrate时遇到的database.yml问题!!

本人无ruby、rail、mysql等使用经验。
最近从github上安装一个本地用的数据库时,遇到了一些问题。
系统为Ubuntu22.04.
我首先在mysql中输入了如下代码:

mysql> CREATE USER 'topo'@'localhost' IDENTIFIED BY 'passwordXXXXXXXX';
mysql> CREATE DATABASE 'topo_database';
mysql> GRANT ALL PRIVILEGES ON topo_database.* TO 'topo'@'localhost';
\q

然后使用rbenv安装了ruby2.5.1、rails6.7+、bundler2.3+等。
已经使用

bundle install

成功安装软件,然后使用

rails db:migrate

时,错误输出结果:

rails aborted!
Mysql2::Error::ConnectionError: Access denied for user 'developer'@'localhost' (using password: YES)
/home/duan/TopoDB/bin/rails:9:in `<top (required)>'
/home/duan/TopoDB/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

我查到可能是config/database.yml的内容问题,但是我也不会改。database.yml内容如下:

#
# default: &default
#   adapter: sqlite3
#   pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
#   timeout: 5000

development:
  adapter: mysql2
  database: topo_dev
  username: developer
  password: dev123
  host: 127.0.0.1
  port: 3306

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  database: topo_dev_test
  username: developer
  password: dev123
  host: 127.0.0.1
  port: 3306

# 
production:
  adapter: mysql2
  database: topodb_prod
  username: <%= ENV['TOPODB_USERNAME'] %>
  password: <%= ENV['TOPODB_PASS'] %>

因为我以后不需要使用ruby等编程工具,也没有时间细细学习,所以希望帮一下忙!感谢。

感谢
GX
2022-09-21 19:40
你把development:下面的database:, username:, password:改成数据库里的数据

的回答解决了上面的问题,我可以跑通了。
但是我接下来跑

rails db:seed

又遇到问题了,上面代码输出为:

rails aborted!
ActiveModel::UnknownAttributeError: unknown attribute 'variable_1' for Experiment.
/home/duan/TopoDB/db/seeds.rb:116:in `block in <top (required)>'
/home/duan/TopoDB/db/seeds.rb:106:in `times'
/home/duan/TopoDB/db/seeds.rb:106:in `<top (required)>'
/home/duan/TopoDB/bin/rails:9:in `<top (required)>'
/home/duan/TopoDB/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)

然后seeds.rb涉及到的106行、116行内容为:

7             ep1 = Faker::Number.within(range: 2..10)
 98             Mouse.new(:cage_id => cage.id, :sex => sx, :genotype => Faker::Number.within(range: 2..4), :dob => db , :weaning_date => db + 21, :three_digit_co    de => dgn,
 99                     :biopsy_collection_date => db + 12, :ear_punch => ep1 , :tdc_generated => Time.now, :strain => cage.strain, :removed => nil, :pup => fals    e ).save(validate:false)
100             dgn += 1
101         end
102     end
103 end
104 
105 # create experiments
106 5.times do
107     name = Faker::Lorem.sentence(word_count:3)
108     date = Faker::Date.between(from:1.year.ago,to:Date.today)
109     desc = Faker::Lorem.paragraph(sentence_count:3)
110     gene = Mouse.pluck(:strain).uniq[Faker::Number.between(from:0, to: (Mouse.pluck(:strain).uniq.size - 1))]
111     prot = Faker::Lorem.paragraph(sentence_count:3)
112     var1 = "disability"
113     v1row = Faker::Number.between(from:5, to:20)
114     var2 = "weight"
115     v2row = Faker::Number.between(from:5, to:20)
116     Experiment.create(name:name, date:date, description:desc, gene:gene, variable_1:var1, variable_1_rows:v1row, variable_2:var2, variable_2_rows:v2row, prot    ocol:prot)
117 end

求解决方法!
这是github网站:https://github.com/UCSF-MS-DCC/TopoDB

database.yml中的用户名和密码根你创建的用户名和密码不一致