MySQL Rails / MySQL2:错误 - 未知数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5754895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:36:34  来源:igfitidea点击:

Rails / MySQL2: Error - Unknown database

mysqlrubyruby-on-rails-3macos

提问by KidKola

I'm following a basic tutorial in Linda. I have been able to install everything properly now, but when I start my Rails server I get this message when I visit localhost:3000:

我正在学习 Linda 的基本教程。我现在已经能够正确安装所有内容,但是当我启动 Rails 服务器时,我在访问时收到此消息localhost:3000

Unknown database 'simple_cms_development'

and then

进而

Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (23.5ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (29.8ms)

回答by Dan Cheail

Have you created the database in MySQL? You should be able to run rake db:createand have Rails create it for you.

您是否在 MySQL 中创建了数据库?您应该能够运行rake db:create并让 Rails 为您创建它。

回答by sami

I had the same error, please run the following command on the Command Prompt:

我有同样的错误,请在命令提示符下运行以下命令:

rake db:create 

to solve the problem.

来解决问题。

回答by Jatin Ganhotra

Look for the answers of these questions:

寻找这些问题的答案:

  1. Have you installed the mysql2 gem?
  2. Is it mentioned in your Gemfile?
  3. Did you run the command rake db:create?
  1. 您是否安装了 mysql2 gem?
  2. 它在你的 Gemfile 中提到了吗?
  3. 你运行命令了rake db:create吗?

回答by hken27

Sometimes creating database with rake causes issues.

有时使用 rake 创建数据库会导致问题。

You can also create the database inside mysql

也可以在mysql里面创建数据库

Make sure mysql is in the root %PATH% in command prompt type echo %PATH% to check.

确保 mysql 位于命令提示符中的根 %PATH% 中,键入 echo %PATH% 进行检查。

If it isn't in your PATH. Then do a quick google search on windows PATH to get instructions

如果它不在您的 PATH 中。然后在 Windows PATH 上进行快速谷歌搜索以获取说明

Open command prompt

打开命令提示符

type mysql -u root -p

输入 mysql -u root -p

type your password that you created for your root

输入您为 root 创建的密码

To create database

创建数据库

create database simple_cms_development

创建数据库 simple_cms_development

done

完毕

回答by Arvind

was getting the same error but caused was different

得到相同的错误,但导致不同

Mysql2::Error: Unknown database 'rdddd_development'

/Users/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in connect' /Users/commeasure/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:ininitialize

/Users/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:inconnect' /Users/commeasure/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in初始化

faced this error due to the created method dynamically, code is here

由于动态创建的方法而面临此错误,代码在这里

Role.all.map(&:name).map(&:parameterize).map(&:underscore).each do |name|
    define_method("#{name.to_sym}?") do
     role.name == name.upcase
    end
  end

How do I fix this for the temporary purpose just comment it out

我如何解决这个临时目的只是将其注释掉