Rails : rake db:create mysql error - mysql

I am trying to setup a mysql database, but I am getting this error message:
rake db:create
(in /Users/yookd/Desktop/rails/blog)
WARNING: Global access to Rake DSL methods is deprecated. Please Include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Blog::Application#task called at /Library/Ruby/Gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
db/test.sqlite3 already exists
rake aborted!
uninitialized constant Mysql2
Tasks: TOP => db:create
(See full trace by running task with --trace)
Any assistance with this?
(following directions on http://guides.rubyonrails.org/getting_started.html)
EDIT:::
How can I use mysql as my database as opposed to sqlite? In the gemfile, it explicitly states: gem 'sqlite'... do I need to replace that line with something like gem mysql?

This is a known issue. See: Rails - rake db:create error
BUT note that Rake 0.9.1 has been released which supposedly fixes things. So first try upgrading rake with:
gem update rake
And update your bundle:
bundle update rake

For your edit, yes, to use mysql you have to first have mysql installed and configured on your system. Then in your gemfile, remove 'gem sqlite' and replace it with:
gem 'mysql'
Then, in your config/database.yml, set it up something similar to:
development:
adapter: mysql
database: name_of_database
pool: 5
timeout: 5000
host: localhost
password: mysql_password
Do the same for test and production.

Related

RoR Rake 10.4.2 Error: "Don't know how to build task 'db:'"

I want to create a MySQL database in Ruby on Rails using:
rake db: create
But it gives me out an error:
rake aborted! Don't know how to build task 'db:'
I am running Ubuntu and cant find answers on the internet about my version of rake (10.4.2).
It's rake db:create without a blank between db: and create.
If you type rake -T you can find the available rake tasks with their proper names.

How to install MySQL for OpenProject?

I follow OpenProject installation. My OS is Window-7. When I execute bundle exec rake db:create:all, I get as below
C:\Sites\openproject>bundle exec rake db:create:all
DL is deprecated, please use Fiddle
require 'rails/all'... 2.277s
Bundler.require... 5.071s
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansic
on/) to get coloured output on Windows
rake aborted!
LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-a
dapter` (cannot load such file -- mysql2/2.0/mysql2)
Tasks: TOP => db:create:all
(See full trace by running task with --trace)
That's why, I execute gem install activerecord-mysql2-adapter as console said. Now, it is ok as below.
C:\Sites\openproject>gem install activerecord-mysql2-adapter
Successfully installed activerecord-mysql2-adapter-0.0.3
Parsing documentation for activerecord-mysql2-adapter-0.0.3
1 gem installed
I execute bundle exec rake db:create:all again, I get error again
C:\Sites\openproject>bundle exec rake db:create:all
DL is deprecated, please use Fiddle
require 'rails/all'... 2.433s
Bundler.require... 5.055s
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansic
on/) to get coloured output on Windows
rake aborted!
LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-a
dapter` (cannot load such file -- mysql2/2.0/mysql2)
Tasks: TOP => db:create:all
(See full trace by running task with --trace)
What I need to do? T_T

Heroku installing Amazon RDS : mysql or mysql2?

I'm installed the Amazon RDS Add-on in Heroku, and created OK an instance in Amazon AWS. But I can't run
heroku run rake db:migrate
It's ending with
(...)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
undefined method `accept' for nil:NilClass
/app/vendor/bundle/ruby/1.9.1/gems/activerecord- 3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:38:in `select_values'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:587:in `get_all_versions'
When I created my instance I followed the instructions from Heroku :
$ heroku addons:add amazon_rds url=mysql2://user:pass#rdshostname.amazonaws.com/databasename
And since then, I'm fighting with Mysql2. First I noticed in Heroku that it was pointing to
mysql://user:pass#mydatabase.us-east-1.rds.amazonaws.com/MyFirstDb
Is it normal that there is no 2 like mysql2://user ? I added it. I changed my Gemfile with
gem 'mysql2', '< 0.3.7'
and my database.yml with
production:
adapter: mysql2
database: db/production.mysql2
before it was set as sqlite3.
I'm newbie, this is my first app that I want to deploy to Amazon AWS so maybe I miss something obvious ! Any idea ?
I got it ! I had forgotten to
gem install activerecord-mysql2-adapter
The error message in Heroku says to run gem install activerecord-mysql-adapter (without the 2), but with the 2, it works perfectly now !
I hope this post will help others. So, to sum up, here is what you need to do :
1- Set the "2" in the add-on link in Heroku
mysql2://user:pass#mydatabase.us-east-1.rds.amazonaws.com/MyFirstDb
2- Add a line to your Gemfile :
gem 'mysql2', '~> 0.3.11'
3- Change your database.yml
production:
adapter: mysql2
database: db/production.mysql2
4- Run
gem install activerecord-mysql2
heroku run rake db:migrate
And enjoy ! :-)

Error when running rake db:migrate

I'm following the railscast where Ryan sets up a VPS. But I need to install mysql instead of postgresql.
when I run the cap deploy:cold command, it all seems to run fine, until it runs the bundle, which fails when trying to install the mysql2 gem.
so i logged into the server and installed it manually (the database had already been setup).
but when i run the rake db:migrate command I keep getting this error:
rake aborted!
database configuration does not specify adapter
Tasks: TOP => db:migrate => db:load_config
in the database.yml file i have the following
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: blog_production
pool: 5
username: blog
password: *****
host: localhost
socket: /var/run/mysqld/mysqld.sock
I've edited the socket from default, added and removed the host line, and installed the gem manually, but nothing seems to make it work!
This usually happens when your deployment scripts or the currently logged in user on the VPS have not set the RAILS_ENV environment variable. Then it defaults to 'development' and your database.yml would have no configuration for that environment. So try
RAILS_ENV=production bundle exec rake db:migrate --trace
instead.
Corrupt yml file solved it for me.
Renamed and recreated the database.yml file and it worked.

rake aborted! uninitialized constant Mysql2

Goksel-Eryigits-Mac-mini:blog geryit$ rake db:migrate --trace
(in /Users/geryit/Sites/blog)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Client does not support authentication protocol requested by server; consider upgrading MySQL client
/Users/geryit/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/mysql.rb:453:in `read'
/Users/geryit/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/mysql.rb:130:in `real_connect'
/Users/geryit/.rvm/gems/ruby-1.8.7-p330/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:600:in `connect'
/Users/geryit/.rvm/gems/ruby-1.8.7-p330/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:164:in `initialize
.
.
.
database.yml
development:
adapter: mysql
encoding: utf8
database: test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Have you defined
gem 'mysql2'
in Gemfile? For Rails 3 and Bundler, it's not enough to install the gem, but to include it in Gemfile.
They work together now without any problems. The problem was Mysql version and mysql gem flags. I removed MYSQL 5.5 and installed Mysql 5.1 back. Everything is fixed. Thanks.
I wrote a blog post about installing, it can be helpful : https://geryit.com/blog/installing-mysql-with-rails-on-mac-os-x-snow-leopard/
Try uninstalling the mysql gem. It might be conflicting with the mysql2 gem you're using in your database.yml.
I was getting 'uninitialized constant Mysql' on Snow Leopard and Rails 3. Adding 'mysql' gem to Gemfile fixed it for me.