# Mysql error running ruby script/generate

**URL:** <https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442>\
**Category:** Rails\
**Created:** [November 20, 2005, 6:00pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442 "2005-11-20T18:00:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [November 20, 2005, 6:00pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/1 "2005-11-20T18:00:08Z")

</div>

Hi,

I thought I’d use the weekend to get into RoR but got stuck quite early.  
I’m using RoR with MySQL on my gentoo laptop and am following the depot  
application from “Agile Web D. with Ruby on Rails”.  
My MySQL is running and has got the products table in it. The user is  
called mysql and does not need a password. The database.yml is adapted  
so that it uses that user and also has the right location for the socket  
(I also tried with an empty user):

development:  
adapter: mysql  
database: depot\_development  
username: mysql  
password:  
socket: /var/run/mysqld/mysqld.sock

Here is the output of running the generator script:

wei-fieg@nono depot $ ruby script/generate scaffold Product Admin  
exists app/controllers/  
exists app/helpers/  
create app/views/admin  
exists test/functional/  
dependency model  
exists app/models/  
exists test/unit/  
exists test/fixtures/  
create app/models/product.rb  
create test/unit/product\_test.rb  
create test/fixtures/products.yml  
uninitialized constant Mysql

and here is the list of my installed gems:

wei-fieg@nono depot $ gem list --local

\*\*\* LOCAL GEMS \*\*\*

actionmailer (1.1.3, 1.0.1)  
Service layer for easy email delivery and testing.

actionpack (1.11.0, 1.9.1)  
Web-flow and rendering framework putting the VC in MVC.

actionwebservice (0.9.3, 0.8.1)  
Web service support for Action Pack.

activerecord (1.13.0, 1.11.1)  
Implements the ActiveRecord pattern for ORM.

activesupport (1.2.3, 1.1.1)  
Support and utility classes used by the Rails framework.

mysql (2.7)  
MySQL/Ruby provides the same functions for Ruby programs that the  
MySQL C API provides for C programs.

rails (0.14.3, 0.13.1)  
Web-application framework with template engine, control-flow layer,  
and ORM.

rake (0.6.2, 0.5.3)  
Ruby based make-like utility.

sources (0.0.1)  
This package provides download sources for remote gem installation

Can anyone point me to some solution?

## Thanks

Dominik

---

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [November 20, 2005, 8:02pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/2 "2005-11-20T20:02:54Z")

</div>

Strange that the error has a captial ‘M’

---

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [November 20, 2005, 10:11pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/3 "2005-11-20T22:11:52Z")

</div>

Peter M. wrote:

> Strange that the error has a captial ‘M’

No, that looks about right - there’s a line like:

include Mysql

that’s failed somewhere.

---

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [April 14, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/4 "2006-04-14T19:15:30Z")

</div>

this is pure genius, as, so far no-one has been able to answer my exact  
question, but in one sentence all my problems have vanished, thank you  
so much, after posting/searching forums for the last 3 weeks(i gathered  
from the answers i got that loads of ruby users have the same problem),  
you have solved my problem, i had the exact problem from word go, my  
article at lighttpd [http://forum.lighttpd.net/topic/575#new](http://forum.lighttpd.net/topic/575#new)

> I have found a workaround: simply putting the following line into the  
> file  
> activerecord-1.13.0/lib/active\_record/connection\_adapters/mysql\_adapter.rb  
> solves the problem:
> 
> require ‘active\_record/vendor/mysql.rb’

i agree with you, i would also like to know what is wrong with my Ruby  
setup as there was a missing connection between ruby and mysql.

thanks again

---

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [November 21, 2005, 1:15pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/5 "2005-11-21T13:15:40Z")

</div>

alex wrote:

> Peter M. wrote:
> 
> > Strange that the error has a captial ‘M’
> 
> No, that looks about right - there’s a line like:
> 
> include Mysql
> 
> that’s failed somewhere.

I have found a workaround: simply putting the following line into the  
file  
activerecord-1.13.0/lib/active\_record/connection\_adapters/mysql\_adapter.rb  
solves the problem:

require ‘active\_record/vendor/mysql.rb’

But this is only a hack… I would like to know what’s wrong with my  
setup. I’ll post it if I find it out.

---

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [July 8, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/6 "2006-07-08T17:44:19Z")

</div>

Dominik Wei-Fieg wrote:

> alex wrote:
> 
> > Peter M. wrote:
> > 
> > > Strange that the error has a captial ‘M’
> > 
> > No, that looks about right - there’s a line like:
> > 
> > include Mysql
> > 
> > that’s failed somewhere.
> 
> I have found a workaround: simply putting the following line into the  
> file  
> activerecord-1.13.0/lib/active\_record/connection\_adapters/mysql\_adapter.rb  
> solves the problem:
> 
> require ‘active\_record/vendor/mysql.rb’
> 
> But this is only a hack… I would like to know what’s wrong with my  
> setup. I’ll post it if I find it out.

Fair warning. I originally had the ‘uninitialized constant Mysql’  
problem. I tried the solution here, which has worked for some people.  
For me, however, it caused another error, the “lost connection to mysql  
server during query” error which is discussed here:  
[http://wiki.rubyonrails.org/rails/pages/Mysql+Connection+Problems](http://wiki.rubyonrails.org/rails/pages/Mysql+Connection+Problems)  
I was able to fix both problems by removing the line 'require  
‘active\_record/vendor/mysql.rb’ and properly installing the Mysql gem.

---

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [May 2, 2006, 5:08pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/7 "2006-05-02T17:08:55Z")

</div>

anyone know why this works, or why it was a problem in the first place

> I have found a workaround: simply putting the following line into the  
> file  
> activerecord-1.13.0/lib/active\_record/connection\_adapters/mysql\_adapter.rb  
> solves the problem:
> 
> require ‘active\_record/vendor/mysql.rb’
> 
> But this is only a hack… I would like to know what’s wrong with my  
> setup. I’ll post it if I find it out.

---

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [August 8, 2006, 11:59pm UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/8 "2006-08-08T23:59:52Z")

</div>

Jared wrote:

> Dominik Wei-Fieg wrote:
> 
> > alex wrote:
> > 
> > > Peter M. wrote:
> > > 
> > > > Strange that the error has a captial ‘M’
> > > 
> > > No, that looks about right - there’s a line like:
> > > 
> > > include Mysql
> > > 
> > > that’s failed somewhere.
> > 
> > I have found a workaround: simply putting the following line into the  
> > file  
> > activerecord-1.13.0/lib/active\_record/connection\_adapters/mysql\_adapter.rb  
> > solves the problem:
> > 
> > require ‘active\_record/vendor/mysql.rb’
> > 
> > But this is only a hack… I would like to know what’s wrong with my  
> > setup. I’ll post it if I find it out.
> 
> Fair warning. I originally had the ‘uninitialized constant Mysql’  
> problem. I tried the solution here, which has worked for some people.  
> For me, however, it caused another error, the “lost connection to mysql  
> server during query” error which is discussed here:  
> [http://wiki.rubyonrails.org/rails/pages/Mysql+Connection+Problems](http://wiki.rubyonrails.org/rails/pages/Mysql+Connection+Problems)  
> I was able to fix both problems by removing the line 'require  
> ‘active\_record/vendor/mysql.rb’ and properly installing the Mysql gem.

doing the require ‘active\_record/vendor/mysql.rb’ doesn’t use the mysql  
gem.  
you get the ver, it caused another error, the "lost connection to mysql

> server during query" error which is discussed here:  
> [http://wiki.rubyonrails.org/rails/pages/Mysql+Connection+Problems](http://wiki.rubyonrails.org/rails/pages/Mysql+Connection+Problems)  
> I was able to fix both problems by removing the line 'require  
> ‘active\_record/vendor/mysql.rb’ and properly installing the Mysql gem.

doing the require ‘active\_record/vendor/mysql.rb’ doesn’t use the mysql  
gem.  
you get the ‘uninitialized constant Mysql’ message because the load of  
the mysql gem failed, but didnt’ raise an exception. if it had the above  
require would have been called. the problem is with mysql\_config. the  
fix is below

[http://www.mail-archive.com/removed\_email\_address@domain.invalid/msg27851.html](http://www.mail-archive.com/removed_email_address@domain.invalid/msg27851.html)

unless there is a way to pass in ldflags to a gem install(i didn’t find  
a way) you will need to edit mysql\_config directly. do an uninstall of  
the mysql gem and then reinstall and remove that require. i am using  
mysql-5.0.22  
hope this helps.

---

<div class="post-metadata">

**Author:** ![Dominik\_Wei-Fieg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@Dominik\_Wei-Fieg](https://www.ruby-forum.com/u/Dominik_Wei-Fieg)\
**Post date:** [November 13, 2006, 9:55am UTC](https://www.ruby-forum.com/t/mysql-error-running-ruby-script-generate/48442/9 "2006-11-13T09:55:56Z")

</div>

Hi all

This is an issue with mysql 5.  
Install mysql 4 then:  
#gem uninstall mysql  
#gem install mysql – --with-mysql-dir=/usr/local/mysql

Hope this helps  
Graeme
