Heroku installing Amazon RDS : mysql or mysql2? - mysql

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 ! :-)

Related

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

mysql compatability error - rake aborted error on rake db:create

I'm a starter in ROR
I' m using ruby 1.9.3 and rails 3.2.1
This is what appears on using rake db:create command
**>rake db:create
rake aborted!
Please install the mysql adapter: 'gem install activerecord-mysql-adapter' <can't activate mysql <~> 2.8.1>, already activated mysql-2.9.0-x86-mingw32. Make sur all dependancies are added to Gemfile.>**
Have installed mysql gem and copied libmysql.dll file to Ruby193/bin (Phpmyadmin and xampp also works good).
Please help me to solve this issue.
Looks like you have to add mysql2 gem into your Gemfile.
Take a look at this answer: Rails mysql2 undefined method
If this doesn't solve your problem, paste the contents of your Gemfile.

Rails : rake db:create mysql error

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.

How to tell heroku to use rails 3 and ruby 1.9.2 for a newly created app?

I created a new app on my machine using rvm ruby1.9.2p0 and rails 3.0.1, and did the following:
rails new -J -d mysql appname
git init
git add .
git commit
heroku create
and the app is created. but when i do:
heroku rake db:create --trace
I get:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql2", "database"=>"app_production", "pool"=>5, "password"=>nil, "socket"=>"/var/run/mysqld/mysqld.sock"}, charset: utf8, collation: utf8_unicode_ci
(in /app)
** 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
and when i do:
heroku rake db:migrate --trace, then the trace has lines like:
/app/.bundle/gems/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:590:in
which shows it is using ruby 1.8 instead of ruby 1.9.2
How can I create a database on my heroku app and make it use ruby 1.9.2p0?
If you've already created the application on Heroku it will have defaulted to 1.8.7 as you've found. You can specify the stack to create the application on when you create your app;
heroku create myapp --stack bamboo-mri-1.9.2
To migrate your app to 1.9.2 you will need to issue
heroku stack:migrate bamboo-mri-1.9.2
Once migrated you will need to repush your application (if i remember correctly)
The problem is not the Ruby or Rails version.
The problem here is that you are trying to use MySQL while Heroku only supports PostgreSQL.
In this page you can find the instructions to migrate to a different Heroku stack.

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.