1

I have following configuration:

Ruby version              1.9.2 (i386-mingw32)
RubyGems version          1.7.2
Rack version              1.2
Rails version             3.0.3
Active Record version     3.0.1
Action Pack version       3.0.3
Active Resource version   3.0.3
Action Mailer version     3.0.3
Active Support version    3.0.3

I am running rake db:create command but it returns nothing and using trace, I find following output on the screen

E:\Crawler\server>rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
rake aborted!

C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:312:in `query'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:312:in `execute

When I run rake db:migrate command, it returns following:

E:\Crawler\server> rake db:migrate
rake aborted!
Unknown database 'marketplace_development'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

My rake file is:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake'

module ::Marketplace
  class Application
    include Rake::DSL
  end
end

module ::RakeFileUtils
  extend Rake::FileUtilsExt
end

Marketplace::Application.load_tasks

database.yml file:

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql2
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: Marketplace_development
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

Can anybody tell me what's happening here? I have not created any database explicitly on my own. Do I need to create a database with some tool? I have seen other SO threads but no avail.

Edit1::

As suggested by Rogier, I opened up MySQL command line client and ran following command

create schema marketplace_development;

Now both commands db:create and db:migrate hang up upon execution.

Edit2::

Every time I restart my command window and start a server with rails server, it asks me to install now ActiveRecord mysql2. I install with gem install activerecord-msql2-adpater, uninstall mysql2 (0.3.11-x86-ming32) , update my Gemfile.lock file to just have mysql2 (0.2.7) .

I run bundle install and start my rails server which is started successfully. But I am not able to view the server in browser. http://localhost:3000 and http://127.0.0.1:3000 never return the page. I have tried with port 30001 also, but in vain.

Edit3

I stopped my server, created a new rails project rails new myApp , moved into folder myApp and started the server. It asked me to do bundle install because it couldn't find sqlite3 ruby. I did so, and started the server and I was able to browse it through above URL.

I moved to my previous server folder and it still doesn't work. What could be wrong in this application?

  • Have you given proper database credentials in database.yml file? – VenkatK Dec 11 '12 at 11:40
  • I mean to say, rails will configure database credentials as `username: '', and password: 'root'`. So change there if you have your own credentials. – VenkatK Dec 11 '12 at 11:45
  • When installing mysql, I didn't provide any password for root, so I assume, there is no password for root. And I didn't create any database either. Should I create it with some tool? Toad 6.3? Thanks. – user1890924 Dec 11 '12 at 11:46
  • Ok..do one thing. Open your mysql GUI. And do let me know with what credentials you have gone inside. – VenkatK Dec 11 '12 at 11:48
  • If your username is root, and password is not for the root. Change the database.yml file as I will send to in the answer box. – VenkatK Dec 11 '12 at 11:51
  • Sorry for late response. When I open MySQL 5.5 command line client, it asks for password. I just press enter and then it shows me command prompt for inputs like mysql> . – user1890924 Dec 11 '12 at 12:12

3 Answers3

1

Keep your db name lowercase (mysql can be case sensitive).

You can create a db simple by using mysql command:

mysql -u root -p
create schema marketplace_development;
quit

the above command is anyway useful to check if the credentials are working properly.

see if the migration then works.

db:create should create the db for you

for all db tasks:

rake -T db

try this basic example:

// im running
MySQL 5.5.25-log
Rails 3.2.2

// from the command line try this
rails new my_sql_test -d mysql

// if the gems are not installed, then run:
bundle install

// update your user/pass
rake db:create
// you get no response

mysql -u root
show schemas; 

// schema is created?
Roger
  • 7,535
  • 5
  • 41
  • 63
  • I changed Marketplace to lower letter marketplace but it didn't work. And on the MySQL command Client, I ran mysql> create schema marketplace_development; And result was = Query OK, 1 row affected (0.00 sec). After this, migrate command also hangs up like create command. – user1890924 Dec 11 '12 at 12:10
  • did you try to reinstall your mysql2 adapter? – Roger Dec 11 '12 at 13:32
  • I tried it also. Please see Edit2 if that was you were suggesting? – user1890924 Dec 12 '12 at 00:36
  • your edit2 is about sqlite? i added a simple example, give it a try (to narrow it down). For me after using 'rails new' it installs the gems. you might (depending on the Rails version) run 'bundle install' – Roger Dec 12 '12 at 08:23
  • thanks for your response. I got everything working as I posted Answer below. It's just I am not able to mark it as a Answer within next 16 hours. – user1890924 Dec 12 '12 at 20:13
  • Great! it was the socket? depending on os and config its not always written in /tmp/mysql.sock (you need to check your my.cnf for that). – Roger Dec 12 '12 at 20:43
  • No. It was not about socket. I left my database.yml as default (given above). It was just installation of wrong versions for both Ruby, Rails and mysql2. – user1890924 Dec 13 '12 at 00:22
  • sure,no problem. please mark this question solved. so it doesn't show up under 'unsolved questions', thanks ;-) – Roger Dec 13 '12 at 09:45
1

After making Edit3, I realized that there might be something wrong with my own project in terms of required dependencies. During the course of installation, I faced many issues and to solve them, I tried every tip given on SO and other forums without knowing even if it's compatible with my existing installation or not. Initially I installed Ruby 1.8.7 and rails 3.1.x without looking at Gemfile, which as a newbie I didn't know its purpose. Then I installed Ruby 1.9.2 and started doing random installations.

And on them was installation of rake 10.0.2 while my project required rake 0.8.7. Since I didn't know much about which rails server is compatible with which version of Ruby, I was trying installation whatever was given on internet, desperately wanting it to be working. Bad thing to do!!

Solution:

I uninstalled rake 10.0.2 and went back to rake 0.8.7. This solution helped me to get it working. Uninstalled mysql (0.3.11) and installed mysql2 (0.2.7)

Lesson learnt: Don't do random installations without looking at project requirements.

Community
  • 1
  • 1
0

If your username is root, and password is not for the root. Change the database.yml file as follows:

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

I think, the above will work for you. Go ahead.

VenkatK
  • 1,295
  • 1
  • 9
  • 21
  • Write `host: 127.0.0.1` instead `host: localhost` once. – VenkatK Dec 11 '12 at 12:16
  • Tried both migrate and create commands, no luck. I also commented and uncommented this line 'socket: /tmp/mysql.sock ' but both commands just hang up upon execution. – user1890924 Dec 11 '12 at 12:24