Why does Rails say "cannot load such file mysql/mysql_api"? - mysql

I was following a tutorial on lynda.com (RoR 3: Section 6, ep. 3) and after installing MySQL and running:
rake db:schema:dump
I got:
rake aborted! cannot load such file mysql/mysql_api
C:/Sites/demo/config/application.rb:7:in '<top <required>>'
C:/Sites/demo/Rakefile:4:in 'require'
C:/Sites/demo/Rakefile:4:in '<top <required>>'
I did copy:
libmySQL.dll
To:
C:\RailsInstaller\Ruby1.9.3\bin
and I also tried uninstalling and installing the mysql gem a couple of times.

I think your problem is similar to cannot load such file -- mysql/mysql_api.
If you are trying to access 64 bit MySQL from 32 bit Ruby then you might encounter this.

Related

Ruby on Rails 4 select schema_migrations Error

Guy today i was open old Ruby project
after copy the files to my Sites folder then run this commands
bundle
rake db:create
rake db:migrate
rails s
when i was open my project on the browser i found the project gives me errors because
MySQL not work with me also i got this error on the console
ActiveRecord::SchemaMigation Load (68.0ms) select 'schema_migrations'.* from 'schema_migrations'
processing by HomeController#index as HTML
Completed 500 Internal Server Error in 92ms
log writing faild. invalid byte sequence in US-ASCII
so why i got this error and how i can solve that ??
I solved it now
just to solve the US-ASCII issue
i added this line to the first line in my model page
#encoding: utf-8
also i added the lines
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
in my Gemfile
then i got another error told me use protected_attributes
so i added the line
gem 'protected_attributes'
in my Gemfile and then execute:
$ bundle

NameError: cannot load Java class com.mysql.jdbc.Driver

I'm using JRuby 1.7.2, along with DataMapper, and I'm getting an error I can't find an answer to.
I'm just testing out DataMapper along with MySQL 5.5 to see if it will run fine when I build around it. Here's the file I'm testing:
require "data_mapper"
require "keys"
DataMapper.setup(:default, "mysql://#{$user}:#{$pass}#localhost/test_db")
And when I run this, I get the error:
NameError: cannot load Java class com.mysql.jdbc.Driver
And it points to the DataMapper.setup line.
My Gemfile should be alright:
source :rubygems
gem "sinatra"
gem "trinidad"
gem "data_mapper"
# do a `sudo apt-get install libmysqlclient-dev` first
gem "dm-mysql-adapter"
gem "jdbc-mysql"
Is there anything I'm missing? I have MySQL set up with a user/pass locally already.
This is a common error when running JDBC clients for MySQL. You need to make sure you have mysql-connector-java-bin.jar on the classpath. You can download it from here.
I'm using Rails 3.2.9 and to solve the problem I added this to my application.rb
if defined? JRUBY_VERSION
require 'jdbc/mysql'
Jdbc::MySQL.load_driver
end
actually, the correct answer is to work-around an incompatibility between 5.1.13 and 5.1.22 !
jdbc-mysql gem already contains the mysql-connector.jar it just ain't auto-loading anymore :
https://github.com/jruby/activerecord-jdbc-adapter/tree/master/jdbc-mysql (read the README)
you can also force the driver to auto-load using a Java system property e.g. from a cmd line :
jruby -J-Darjdbc.mysql.autoload=true -S rake ...
I had the same error when trying to use a mysql database from jruby/rails4. In my case this line was missing from ./Gemfile:
gem 'jdbc-mysql'

no such file to load -- redis-namespace

I am working on Rails 2.3.8. I have following in my environment.rb
config.gem "redis"
config.gem "redis-namespace", :lib => "redis/namespace"
When I list my redis gems then I see:
redis (2.0.3)
redis-namespace(0.7.0)
When I run rake gems:install then I get an error that says:
no such file to load -- redis-namespace
Shouldn't requiring "redis/namespace" solve the issue? Can anyone please help me with this?
It sounds as if rake gems:install depends on the very gem it is trying to install.
Try using rails_gem_install or bundler instead.

can't run migration

I run
rake db:create
and getting strange error
rake aborted!
126: ═х эрщфхэ єърчрээ√щ ьюфєы№. - C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-
0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so
I tried to reinstall bundler.
Is it gem problem ?
To solve this problem, reference to the following link:
http://maxivak.com/installing-mysql2-gem-on-ruby-1-9-2-and-rails-3-0-5-on-windows/
You need to include mysql-connector through the Rails DevKit.

Wordpress to Jekyll script throwing error

I've been wrestling with this problem for a day or so and cannot figure out what's going on. I'm trying to run a script to import my Wordpress .sql into Jekyll and convert everything to markdown. But every time I run the script (on both Mac and Ubuntu) I'm getting an error. I'm at a loss of what to do. Here's my terminal output and gem list:
jason#ubuntu:~$ ruby -r './wordpress.rb' -e 'Jekyll::WordPress.process( "#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")'
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': LoadError: no such file to load -- mysql (Sequel::AdapterNotFound)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/adapters/mysql.rb:4
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `k_require'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:249:in `tsk_require'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:72:in `check_requiring_thread'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:69:in `synchronize'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:69:in `check_requiring_thread'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:249:in `tsk_require'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/database/connecting.rb:25:in `adapter_class'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/database/connecting.rb:63:in `connect'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:119:in `connect'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:282:in `adapter_method'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:289:in `mysql'
from ./wordpress.rb:35:in `process'
from -e:1
jason#ubuntu:~$ gem list
*** LOCAL GEMS ***
classifier (1.3.3)
directory_watcher (1.4.0)
fast-stemmer (1.0.0)
jekyll (0.10.0)
liquid (2.2.2)
maruku (0.6.0)
sequel (3.22.0)
syntax (1.0.0)
I'm using Paul Stamatiou's adapted script. Thanks ahead of time for any suggestions!
If you focus on the actual error message:
LoadError: no such file to load -- mysql
It's fairly obvious that you need to install the mysql gem:
gem install mysql