I've recently upgraded to Rails 3 and am getting the following issue when trying to run rake db:create to create a mysql database of which has been defined in database.yml
Some info about my setup:
running snow leopard
rails gem v3.0.3
mysql gem v2.8.1
mysql 5.5.8
I'm presented with this issue:
$rake db:create
(in /Users/elliottheis/Sites/demoProject)
rake aborted!
uninitialized constant Mysql::Error
(See full trace by running task with --trace)
Does anyone have any ideas how to solve this, it's driving me nuts!
Make sure Mysql is in your Gemfile and the database.yml is setup for Mysql. Uninitialized constant simply and will most likely always mean you have not told Rails where to find it. It you can type mysql -uroot into Terminal and see the Version then you know that MySql is fine. Try post a bit more information and we will see if we cant get to the bottom of this.
rake -r mysql db:create --trace
If this does not work then something has gone wrong in the installation. Try This.
Uninstall Mysql - Follow these instructions
Reinstall Mysql - Follow these instructions
Let us know how you get on and tell us the solution when you get it. All the best
I know this has already been answered, but in case this happens to someone else, my issue was identical to Elliot's.
However, my fix revolved around using mysql gem 2.8 and Snow Leopard, which which is explained in another Stackoverflow thread:
As it turns out, that class should not exist; the error message is
caused by a problem with the latest Mysql driver. mysql-2.8.1 looked
for my libraries in a directory named with an extra level of ‘mysql’
at the end. For instance, my libraries (under MacOS X 10.5.8), are in
/usr/local/mysql/lib, but the mysql.bundle library looks for the MySQL
libraries at /usr/local/mysql/lib/mysql … which is wrong.
So I needed to install the mysql gem version before 2.8. Follow the instructions on this Web site, and your issue should be resolved.
Related
/redmine$ ruby script/server -e production
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
/home/siya/.rvm/gems/ruby-1.8.7-p330/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
/home/siya/.rvm/gems/ruby-1.8.7-p330/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:589:in real_connect': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (Mysql::Error)
from /home/siya/.rvm/gems/ruby-1.8.7-p330/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:589:inconnect'
This issue occur's when I restart my application. In fact yesterday it was running fine. But today I tried a lot and searched the web, but could not get success.
After googling, I got one command to update the system ie sudo gem update --system
Now new error occurs:
/home/siya/.rvm/gems/ruby-1.8.7-p330/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
from /home/siya/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
Upgrade rails to the latest version (2.3.5 is fairly old).
gem install rails --version 2.3.11
You will also need to update your dependencies in your environment.rb, to set RAILS_GEM_VERSION to 2.3.11
Run rake rails:update
Test! Rails upgrades seem to rarely be seamless. You do have an extensive suite of unit tests, don't you... :)
Some-time, In resolving such type of issues. We again raise any other conflict.
So best part is that,just take the
bakcup of application folder and
public folder. Re-install the whole
rails and ruby.
Because after investing whole day to resolve this issue. I followed this procedure. Please do not waste time.
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)
I've been fighting with a Rails install on my Mac for some time. The error I'm getting (in my development log) says:
Status: 500 Internal Server Error no such file to load -- mysql
Here's some info:
I can successfully rake db:migrate my application.
I've installed the MySQL gem and it appears in the gem list: mysql (2.8.1).
I have Passenger installed.
The error comes from an existing rails app that works on our production server.
Creating a new Rails app, a new MySQL db (using mysqladmin -uroot create sampledb) works fine.
I've googled this and can't find anything specific to this error. There are a few related results where the solutions relate to paths when installing the MySQL gem. For example,
sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
Has anyone else experienced this issue or suggest a solution?
Thanks for the response - the good news is, the problem is solved.
The bad news - I'm not entirely sure what fixed it. I can tell you this: it had something to do with the mysql gem install and all the flags pointing to lib, include and config. There are probably a dozen different versions of the same command floating around out there for Mac OS X Leopard.
The odd thing was that ruby appeared to be connected to mysql on some level (it's ability to rake db for example) but broke when actually loading a page.
The gem install string that ended up working was this:
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I'd love some clarification on the how's & why's of this. This worked for me, but doesn't include pointers to the app directory, the lib directory or the include directory.
Do you have multiple ruby installed? Try invoking this command to find out: whereis ruby
Which ruby version is you passenger using? You can check this from your apache or nginx configuration
Is the ruby version passenger is using the same as ruby you are using from the command line?
Is mysql gem installed on that ruby version?
Double check if the mysql bin path is in your $PATH system environment variable. If you execute
*echo $PATH*
there must be displayed something like
*/usr/local/mysql/bin*
You can also type
mysql and then the tab-key twice.
If if this doesn't bring up a list of mysql commands (like mysqladmin etc.) the mysql bin path is not set ccorrectly. You can set it by adding the correct directory to your bash profile file.
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
Please verify up front if
*/usr/local/mysql/bin*
really contains the mysql commands on your Mac. Important: close and reopen the terminal window to make changes work.
I'm trying to get a database populate so I can begin working on a project. This project is already built and I'm being brought in to help with front-end work. Problem is I can't get rake db:migrate to do any inserts. Every time I run rake db:migrate I get this:
== 20081220084043 CreateTimeDimension: migrating ==============================
-- create_table(:time_dimension)
-> 0.0870s
INSERT time_dimension(time_key, `year`, `month`, `day`, day_of_week, weekend, quarter) VALUES(20080101, 2008, 1, 1, 'Tuesday', false, 1)
rake aborted!
Could not load driver (uninitialized constant Mysql::Driver)
I'm building on a MBP with Snow Leopard. I've installed XCode from the
disk that comes with the mac. I've updated ruby, installed rails and
all the needed gems. I have the 64 bit version of MySQL installed.
I've tried the 32 bit version of MySQL and I've even tried installing from macports.
The mysql gem is installed using: sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/path/to/mysql/bin/mysql_config
the migrate creates the tables just fine but it dies every single time it tries an insert.
Any help would be great
These instructions for installing MySQL worked great for me on Mac OS X Snow Leopard: http://hivelogic.com/articles/compiling-mysql-on-snow-leopard
If running 'mysql -u root' on your console works fine, then possibly reinstall your mysql gem using the instructions from hivelogic.com (as per John Topley's link) by typing this instead:
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
If you installed MySQL 64-bit as a pkg, try reinstalling by manual compile.
Tip on a side: Database migration is bad for seeding. If you use rails >= 2.3.4 then you should use db/seeds.rb and $ rake db:seed task for this.
Given the error you were getting, it looks like you haven't required the mysql gem.
Other potential gotchas:
You forgot to restart your application/server after installing the gem.
You have some sort of problem with the mysql user permissions. (eg: no write privs)
You're using the wrong mysql driver/gem.
Edit: If you're doing ruby dev on Mac, I highly recommend using both homebrew and rvm.
I had trouble with the gem at first but got it to work when I installed the 64-bit MySQL and reinsatlled the gem with arch flags.
So it work in rails. The error I used to get was
uninitialized constant MysqlCompat::MysqlRes
but that is now gone :)
However in Xcode when I run a RubyCocoa project I still get the old error of
uninitialized constant MysqlCompat::MysqlRes
Does anyone know why this may be?
Is it because the gdb is 64-bit?
How can it work in Rails but not in RubyCocoa?
A little debugging shows that it fails to load mysql_api.bundle
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle:
dlopen(/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle, 9): no suitable image found.
Did find: (LoadError) /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle: mach-o, but wrong architecture -
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
The problem might be that xcode uses another version of the ruby framework than you are using normally, I had that trouble and solved it somehow.
The architecture mismatch might be some other thing though:
/System/Library/Frameworks/Ruby.framework
I had the same problem and it had something to do with an older MySQL installation if I remember correctly. I installed the 32-bit version by accident, noticed the mistake and installed the 64-bit one.
I got rid of the error by removing MySQL as described here: How do you uninstall MySQL from Mac OS X and reinstalling the latest version with arch flags.
Did you try this?