Help with "rake db:migrate" error please?

Hi,

Just trying to get my first database based rails app up on
dreamhost.com. The app was working prior to putting in mysql DB usage
but I’m just stuck on getting the app working with mysql. I’ve already
created the database and can connect to it manually.

Below is the error I get after running the rake migrate. It worked OK
on my home PC environment. I did change the enviroment to “test” on the
dreamhost.com site.

Any ideas?

ERROR OUTPUT

[skybar]$ rake db:migrate --trace
(in /home/.granger/callagga/testapp.gregnet.org)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Can’t connect to local MySQL server through socket
‘/var/run/mysqld/mysqld.sock’ (2)
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/mysql_adapter.rb:331:in
real_connect' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/mysql_adapter.rb:331:inconnect’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/mysql_adapter.rb:88:in
initialize' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/mysql_adapter.rb:37:innew’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/mysql_adapter.rb:37:in
mysql_connection' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:insend’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:in
connection_without_query_cache=' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/query_cache.rb:54:inconnection=’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in
retrieve_connection' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:inconnection’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:281:in
migrate' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/tasks/databases.rake:4 /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/tasks/databases.rake:3:incall’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:ineach’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:ininvoke’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:ininvoke’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:ineach’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7 /usr/bin/rake:18:inload’
/usr/bin/rake:18

CUT FROM ENVIRONMENT.RB

ENV[‘RAILS_ENV’] ||= ‘test’

thanks in advance
Greg

On 7/23/06, Greg H. [email protected] wrote:

Can’t connect to local MySQL server through socket
‘/var/run/mysqld/mysqld.sock’ (2)

Have you checked that that is where the MySQL socket is?

Sincerely,

Tom L.
http://AllTom.com/
http://GadgetLife.org/

Tks for replying Tom,

Do you mind if I ask what you mean here - I have to admit I’m a windows
person mainly :frowning:

Tks
Greg

Tom L. wrote:

On 7/23/06, Greg H. [email protected] wrote:

Can’t connect to local MySQL server through socket
‘/var/run/mysqld/mysqld.sock’ (2)

Have you checked that that is where the MySQL socket is?

Sincerely,

Tom L.
http://AllTom.com/
http://GadgetLife.org/

Tom, I think your database.yml is misconfigured. It should not use
It should look exactly like this, which connects to MySQL over a TCP
connection:

production:
adapter: mysql
database: your_db
username: your_username
password: your_password
host: yourdb.yourhostname.com
port: 3306

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

tks Dan - it was acutally me with the issue

It seems I can’t get ftp or ssh access to dream host from work at the
moment, however I don’t remember seeing a “port” entry in my config
file. If I had omitted this would this explain the error?

(I just adjusted the out of the box rails settings, and I used the
“TEST” environment, as I still want to be dynamic for testing changes
but did not want to use DEVELOPMENT so I could still test on my local PC
at home without having to change things. So if the PORT line isn’t in
the standard TEST entry in database.yml out of the box from rails then I
wouldn’t have had it in at dreamhost)

Dan K. wrote:

Tom, I think your database.yml is misconfigured. It should not use
It should look exactly like this, which connects to MySQL over a TCP
connection:

production:
adapter: mysql
database: your_db
username: your_username
password: your_password
host: yourdb.yourhostname.com
port: 3306

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

Dan - I’ve been looking for the syntax/documentation for database.yml so
I can firm up my understanding of what you’re suggesting. Can you give
any pointers off hand for where I should look for this?

tks
greg

Dan K. wrote:

I suspect your problem has to do with the test database being
special. It’s designed to be replicated from the development
database schemas and populated with fixtures when you run tests. Try
creating a forth entry in your database.yml called server-devel and
see if you can get that set up correctly.

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

I suspect your problem has to do with the test database being
special. It’s designed to be replicated from the development
database schemas and populated with fixtures when you run tests. Try
creating a forth entry in your database.yml called server-devel and
see if you can get that set up correctly.

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

Actually I’ve just found some info in the Rails API guide (see below).
I’m guessing what is required is the “:socket” option entry to be setup
as follows:

socket: /var/run/mysqld/mysqld.sock

Or actually I’m not sure if this (from the error log) is the incorrect
location that my app was trying, or whether it was the correct one?

If it were the incorrect location then I guess I need to find out where
Dreamhost has the mysqld.sock file located?

Will try this once I get home.

==============
The MySQL adapter will work with both Ruby/MySQL, which is a Ruby-based
MySQL adapter that comes bundled with Active Record, and with the faster
C-based MySQL/Ruby adapter (available both as a gem and from
www.tmtm.org/en/mysql/ruby/).
Options:
* :host â?? Defaults to localhost
* :port â?? Defaults to 3306
* :socket â?? Defaults to /tmp/mysql.sock
* :username â?? Defaults to root
* :password â?? Defaults to nothing
* :database â?? The name of the database. No default, must be
provided.
* :sslkey â?? Necessary to use MySQL with an SSL connection
* :sslcert â?? Necessary to use MySQL with an SSL connection
* :sslcapath â?? Necessary to use MySQL with an SSL connection
* :sslcipher â?? Necessary to use MySQL with an SSL connection

AWDWR chapters 6 & 13, plus read about YAML.

If you’re still having problems, you might consider editing the
database.yml from a fresh rails install (rails temp), as things like
spurious tabs can be hard to debug.

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

I think dreamhost have their mysql database on a different server, hence
their request to put the mysql.youdomain.name in.

I’m still stuck on this for the moment - no response from Dreamhost yet.

Henning K. wrote:

Greg H. wrote:

Actually I’ve just found some info in the Rails API guide (see below).
I’m guessing what is required is the “:socket” option entry to be setup
as follows:

socket: /var/run/mysqld/mysqld.sock

That would be the default socket, which I’m guessing dreamhost isn’t
using. the best option here is probably to go TCP - the socket means
you’re using a “pipe” connection to mysql, i.e. not invoking the TCP
stack.

Just comment out or delete the socket line completely, and setup mysql
host: localhost, port: 3306.

Regards,
Henning K.

Greg H. wrote:

Actually I’ve just found some info in the Rails API guide (see below).
I’m guessing what is required is the “:socket” option entry to be setup
as follows:

socket: /var/run/mysqld/mysqld.sock

That would be the default socket, which I’m guessing dreamhost isn’t
using. the best option here is probably to go TCP - the socket means
you’re using a “pipe” connection to mysql, i.e. not invoking the TCP
stack.

Just comment out or delete the socket line completely, and setup mysql
host: localhost, port: 3306.

Regards,
Henning K.

This is a working dreamhost config. Have you configured your MySQL
correctly on Dreamhost (picking a unique domain name for it, etc.)
Can you connect to it using MYSQLFront on Windows or CocoaMySQL on a
Mac?

production:
adapter: mysql
database: your_db
username: your_username
password: your_password
host: yourdb.yourhostname.com
port: 3306

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

BTW - Whilst the dreamhost wiki
(http://wiki.dreamhost.com/index.php/Ruby_on_Rails) suggests there is no
need for a :socket entry in database.yml I am still getting the "Can’t
connect to local MySQL server through socket
‘/var/run/mysqld/mysqld.sock’ " error when using “rake db:migrate”.

I did check the mysql socket location on dreamhost but I couldn’t see
this directory? Perhaps unix permissions or a real issue? See below:
Any ideas anyone?

[skybar]$ mysql_config --socket
/var/run/mysqld/mysqld.sock
[skybar]$
[skybar]$
[skybar]$ cd /var/run/mysqld
-bash: cd: /var/run/mysqld: No such file or directory

Regards
Greg

PS If anyone has a working dreamhost Ruby on Rails application I’d love
to see an example of your database.yml file.

Tks Dan - One final question of clarification (hopefully)

The “host: yourdb.yourhostname.com” - what would this look like exactly
for a dreamhost site, say where the app is hosted under a subdomain like
subdomain1.mysite.com? Is it supposed to start with “mysql.”?

Dan K. wrote:

This is a working dreamhost config. Have you configured your MySQL
correctly on Dreamhost (picking a unique domain name for it, etc.)
Can you connect to it using MYSQLFront on Windows or CocoaMySQL on a
Mac?

production:
adapter: mysql
database: your_db
username: your_username
password: your_password
host: yourdb.yourhostname.com
port: 3306

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

Hi Dan,

Yes. I’ve set up the database on dreamhost OK, I’m able to connect to
it via “mysql -u dbuser -p -h mysql.gregnet.org databasename”. Also I’m
able to run the app successfully via the “ruby script/server” startup &
then connect to it via port 3000.

I’ll retry again when I’m home using your syntax for the database.yml,
however would you be able to give me an example of your “host” line in
your database.yml? Do you actually use the “mysql” at the start
like “mysql.gregnet.org”?

BTW - Did my previous post re the fact I couldn’t see the winsock file
on dreamhost make sense to you?

ie.
[skybar]$ mysql_config --socket
/var/run/mysqld/mysqld.sock
[skybar]$
[skybar]$
[skybar]$ cd /var/run/mysqld
-bash: cd: /var/run/mysqld: No such file or directory

Thanks again Dan
Greg

As I understand it, there are two ways to talk to MySQL. Via TCP or
via socket. Since it’s on another machine, I believe TCP is your
only option. My host line looks like:

host: exampledb.example.com

But that’s just because I chose to call it exampledb. If you’re able
to run script/server (I would generally use script/console to test my
database connections), I don’t quite understand the problem. Why are
you trying to use mysql_config? Also, note that for both scripts you
need to specify production to get them to connect to the right database.

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

Hi Dan,

I’ll try this syntax when I get home, thanks. I’ll also try the
script/console tip too.

Re “Why are you trying to use mysql_config” - I just used this as I
found advice that suggested “mysql_config --socket” was the way to find
out for your ISP where the mysql.sock file is located.

BTW - Just to reconfirm the “can’t connect to local MySQL server through
socket” error is hitting me as I’m trying to run “rake db:migrate” to
get the tables created in the production database. So I guess I’m
assuming that running this rake command is the acceptable method of
configuring one’s production database.

Thanks again
Greg

Greg, there’s no preconfigured server; you set it up. In
panel.dreamhost.com, select Goodies, Manage MySQL, and your server
will show with its hostname, database name, etc. You might also
consider creating a new database.

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

Doh!

Hey Dan - guess what. The problem was simply that I was using:

rake db:migrate

and not

rake db:migrate RAILS_ENV=“production”

I’d assumed without question that the rake command would be aware of the
PRODUCTION setting I had put in place, but I guess it obviously isn’t
aware of this setting :frowning:

I wonder how I could have picked this up earlier.

Anyway, thats for the help, I’ve learnt lots on the way :slight_smile:
Greg

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs