gpt4 book ai didi

mysql - 无法转储远程数据库

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:55 25 4
gpt4 key购买 nike

我在 database.yml 文件中有这个数据库配置

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: oma_development
pool: 5
username: root
password:
host: localhost

test:
# same as in development section

production:
# same as in development section


development_blacklist:
adapter: mysql2
encoding: utf8
database: webstuff
username: login
password: password
host: remote-database.com

test_blacklist:
adapter: mysql2
encoding: utf8
database: webstuff
username: megas
password:
host: /var/run/mysqld/mysqld.sock

我想执行 rake 任务:

namespace :db do
namespace :schema do
desc 'Dump blacklist database schema'
task :dump => [:environment, :load_config] do
filename = "#{Rails.root}/db/blacklist_schema.rb"
File.open(filename, 'w:utf-8') do |file|
ActiveRecord::Base.establish_connection("development_blacklist")
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
end
end

通过调用这个命令:

rake db:schema:dump

我有错误:

rake aborted!
Access denied for user 'root'@'localhost' (using password: NO)

看来 rake 任务正在尝试从 development 部分连接到数据库。

我不明白为什么 rake 任务试图连接到 development 数据库,而 rake 任务应该连接到 development_blacklist 数据库。

如何设置 rake 任务只连接到 development_blacklist 数据库?

最佳答案

您可以显式设置环境,例如:

$ RAILS_ENV=production rake db:schema:dump

关于mysql - 无法转储远程数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15430697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com