cannot load such file -- mysql/mysql_api - mysql

I am completing the tutorial on Ruby on Rails 3 Essential Training through Lynda.com on Windows 7, and I am in the section on "Databases and Migrations". I am attempting to sync the database I have created in MySQL with my Rails project, however I have been running into an abort message. The instructor asked my class to go through Command Prompt to open up our rails project and perform a Rake to build a "schema.rb" with this code:
rake db:schema:dump
Yet each time I type the code in I have gotten this error message:
C:\Users\User\Documents\simple_cms>rake db:schema:dump
rake aborted!
cannot load such file -- mysql/mysql_api
C:/Users/User/Documents/simple_cms/config/application.rb:7:in `<top (required)>'
C:/Users/User/Documents/simple_cms/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
Some solutions I have attempted:
I have installed the binary version of mysql. It was built using MySQL Connector/C version 6.0.2. and I added
libmySQL.dll
to
C:\RailsInstaller\Ruby1.9.3\bin
from dev.mysql.com
I have attempted to download the "mysql2" Gem through Command Prompt with the following result:
C:\Users\User\Documents\simple_cms>gem install mysql2
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while..
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
Help?

Or just instalo mysql2 gem. It Works for me at Wim 10.

Are you trying to access a 64 bit MySQL installation from 32 bit Ruby installation. This seems to be problem with a lot of ppl, even I encountered this when I had a new Win7(64 bit) new machine.
try the solution provided on this blog :-
http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/

Related

Rake command aborted when I try to use it on someone else's code

I have recently copied Ruby on Rails code from one machine onto mine. I have successfully installed all the proper versions of Ruby and Rails that was on the other machine onto mine. When I try to use the command rake about in the app's directory it gives me this error:
C:\ror\dev\AWI>rake about
rake aborted!
LoadError: cannot load such file -- mysql2/2.4/mysql2
C:/ror/dev/AWI/config/application.rb:8:in `<top (required)>'
C:/ror/dev/AWI/Rakefile:5:in `require_relative'
C:/ror/dev/AWI/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
I believe I have the right version of MySQL2 downloaded onto my machine but it seems like this is what's causing the problem. Any ideas on how to run the rake command on my computer using code taken from a different computer? Thanks

Configuring a Project for a Database Ruby on Rails

So I'm new to programing and I'm teaching myself Ruby on Rails to get started. I have mysql running and I've downloaded Ruby ruby 2.3.0 and Rails 3.2.22.2 because these are the versions being used in the video tutorial.
I was generating a controller & view, however when it came to the moment of truth to see if everything worked there were problems. I programmed index.html.erb to say "hello world" in my browser but received this message:
ActiveRecord::ConnectionNotEstablished
I believe this is because it's trying to contact the database. So I started to create the database on mysml, and as I reach the point where I create a schema.rb in the dp folder. Only when I type the command in terminal I get this:
julian$ rake db:schema:dump
rake aborted!
LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.4. Make sure all dependencies are added to Gemfile.)
/Users/julian/Sites/simple_cms/config/environment.rb:5:in `<top (required)>'
Gem::LoadError: can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.4. Make sure all dependencies are added to Gemfile.
/Users/julian/Sites/simple_cms/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:schema:dump => environment
(See full trace by running task with --trace)
What do I do? I have been stuck on this for hours, does anyone have some guidance?
Please add gem 'activerecord-mysql2-adapter' to your Gemfile
i think you can uninstall the wrong one
gem uninstall <gem_name>
and then install the correct one
gem install <gem_name>

ruby, rubygems & rails - getting everything in the right place!

So - a little bit of background on the system I'm running.
I'm on a Mac running Snow Leopard.
I know that Snow Leopard comes pre-installed with Ruby and Rails - but I think I may have messed things up as I found this out after I installed Ruby and Rails again.
When I run ruby -v it displays that I am running ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]. Even though I've gone through the process to try and install 1.9.2!
When I run rails -v it displays that I am running Rails 2.3.5
When I run mysql -v it displays that I am running 5.1.56 MySQL Community Server (GPL)
I can get into the interactive ruby shell and I can get into mysql prompt.
However, when I try to run ruby script/console, it comes up with:
ruby: No such file or directory -- script/console (LoadError)
Furthermore, when I attempt to setup a new folder for a rails project it comes up with the following:
rails railsproject
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:53:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:53:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support.rb:56
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:53:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:53:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/bin/../lib/rails_generator.rb:28
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:53:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:53:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/bin/rails:14
from /usr/bin/rails:19:in `load'
from /usr/bin/rails:19
Which directory should I have installed the ruby and rubygems folders into?
Also, do I need to be in a specific directory for the ruby script/console command to work properly?
This is very frustrating - as I tried to uninstall and reinstall ruby and rubgygems multiple times...
Complete newbie with this - any help would be greatly appreciated!
Cheers
Rick
My advice would be to remove all existing packages and use the Ruby Version Manager instead. Just visit the page follow the installation instructions and everything will be fine.
Pragmatic Studio has some instructions for ruby 1.9 and rails 3. These are the directions they give students before participating in one of their courses. Pragmatic Studio also publishes a lot of great ruby/rails books so you could say they're a trusted resource.

Segfault when I rake (Ruby on Rails)

EDIT: Here's the solution (in case the thread linked to below disappears):
Install ruby 1.8.6 (down from 1.8.7)
gem install rails -v=2.3.8 (same as before)
gem install mysql (version 2.8.1, same as before)
Download libmysql.dll from http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll and deposit it in Ruby186/bin. (Before, I had copied over the libmysql.dll file from Mysql/bin.)
When I attempt rake db:migrate with the database.yml file configured for mysql (not sqlite3) I get the following segfault error:
C:/Ruby187/lib/ruby/1.8/benchmark.rb:306: [BUG] Segmentation fault
ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
I have already looked at this thread: Ruby on Rails Rake Error and don't see any help there.*** It appears that my rails app is configured correctly because when I run rake db:create, rails successfully creates the mysql schema dictated for the development environment in database.yml (or returns a "schema already exists" message).
I'd guess I had mysql configured incorrectly, but the fact that rake db:create works on it makes me think otherwise. I have successfully set up rails and mysql (working together) on three other machines; I don't know what the problem is on this one.
Ruby v. 1.8.7 -
Rails v. 2.3.8 -
Mysql v. 5.1.54
***The user who posted that thread indicated that he solved the problem thanks to a post on aptana. The link to that post, however, points to the home page, so the answer thread appears to have either been moved or removed.
Does this describe the solution as well? http://rubyat.com/blog/2010/06/rails-2-3-8-segmentation-fault/
I found that the last step, using the instantrails dll, solved my problem on Win 7 x64 without my having to change ruby or rails versions.
ruby -v
ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
rails -v
Rails 3.2.0
gem search mysql
mysql (2.8.1 x86-mingw32)

push Rails3 on Heroku. can not find mysql gem

i'm getting an error when pushing to heroku using rails 3. I'm on windows with ruby 1.8.7
Administrator#WIN-DQC3IH63U7C ~/nasha (master)
$ heroku rake db:migrate
rake aborted!
no such file to load -- mysql
/disk1/home/slugs/280561_9c64ba2_1741/mnt/Rakefile:4
(See full trace by running task with --trace)
(in /disk1/home/slugs/280561_9c64ba2_1741/mnt)
Heroku doesn't use the database you use for running your application locally.
Heroku uses PostgreSQL (http://docs.heroku.com/database)
Did you freeze Rails into vendor? This problem usually appears with Heroku when you freeze Rails. You must leave Heroku use it's own Rails based on your .gems file. You can read more about this here http://docs.heroku.com/gems#heroku-gem-manifest
If this is not the problem, did you follow the instructions regarding Heroku and Rails 3 applications? You can read about it here http://docs.heroku.com/rails3 Please notice that you must setup the Bamboo Stack for your Rails 3 application to work correctly.
You need have the mysql gem in your Gemfile
gem "mysql"