KidKola
KidKola

Reputation: 291

Rails / MySQL2: Error - Unknown database

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:

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)

Upvotes: 28

Views: 35580

Answers (5)

Arvind
Arvind

Reputation: 2781

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

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

Upvotes: 0

sami
sami

Reputation: 169

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

rake db:create 

to solve the problem.

Upvotes: 16

hken27
hken27

Reputation: 413

Sometimes creating database with rake causes issues.

You can also create the database inside mysql

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

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

Open command prompt

type mysql -u root -p

type your password that you created for your root

To create database

create database simple_cms_development

done

Upvotes: 0

dnch
dnch

Reputation: 9605

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

Upvotes: 60

Jatin Ganhotra
Jatin Ganhotra

Reputation: 7025

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 ?

Upvotes: 5

Related Questions