Mysql Can't Connect

I'm on OS X 10.5.8 with the up-to-date Rails. I'm trying to get
restful_authentication to work, but I keep getting a mysql error. I've
done the re-install mysql thing.

[terminal]
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
/Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/vendor/
rails/activerecord/lib/active_record/connection_adapters/
mysql_adapter.rb:576:in `real_connect': Can't connect to local MySQL
server through socket '/var/run/mysqld/mysqld.sock' (2) (Mysql::Error)
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/activerecord/lib/active_record/connection_adapters/
mysql_adapter.rb:576:in `connect'
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/activerecord/lib/active_record/connection_adapters/
mysql_adapter.rb:204:in `initialize'
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/activerecord/lib/active_record/connection_adapters/
mysql_adapter.rb:76:in `new'
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/activerecord/lib/active_record/connection_adapters/
mysql_adapter.rb:76:in `mysql_connection'
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/activerecord/lib/active_record/connection_adapters/
abstract/connection_pool.rb:223:in `send'
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/activerecord/lib/active_record/connection_adapters/
abstract/connection_pool.rb:223:in `new_connection'
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/activerecord/lib/active_record/connection_adapters/
abstract/connection_pool.rb:245:in `checkout_new_connection'
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/activerecord/lib/active_record/connection_adapters/
abstract/connection_pool.rb:188:in `checkout'
   ... 26 levels...
  from /Applications/MAMP/htdocs/Rails/restful_authentication_tutorial/
vendor/rails/railties/lib/commands/server.rb:84
  from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
  from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`require'
  from script/server:3
[/terminal]

I'm on OS X 10.5.8 with the up-to-date Rails. I'm trying to get
restful_authentication to work, but I keep getting a mysql error. I've
done the re-install mysql thing.

Where does MAMP keep its mysql socket ? If it's not /var/run/mysqld
then change your database.yml so that it points at the right place.

Fred

Thanks for the advice, I had that "duh" moment when I read it...having
my Rails apps in the MAMP folder messed up the mysql settings.

I moved my Rails app to the Sites folder on my Mac, I was able to get
mysql to work. Now I'm having problems with my settings somewhere, my
browser is giving me this message:

[browser message]

ActiveRecord::StatementInvalid in Root#index

Showing app/views/root/index.html.erb where line #5 raised:

Mysql::Error: Table 'DEV.invitations' doesn't exist: SHOW FIELDS FROM
`invitations`

Extracted source (around line #5):

2: <% unless logged_in? -%><% if_in_beta? do -%>
3: <%= error_messages_for :invitation %>
4: <p>We are currently in private beta. Please enter your email
address below and we will let know when an invitation becomes
available.</p>
5: <% uberform_for [:user, Invitation.new] do |f| -%>
6: <%= f.text_field :email, :label => "Your Email:" %>
7: <%= f.submit 'Submit' %>
8: <% end -%>

[/browser message]

I have some null values in my database, could that be the source of my
issue?

Thanks, Kevin

This is your problem:
Mysql::Error: Table 'DEV.invitations' doesn't exist: SHOW FIELDS FROM
`invitations`

Do you have a database DEV that has a table invitations? Did you
migrate your database?

Yes, I did migrate the database. But I ran a rake db:migrate again to
be positive and I get this error.

Mysql::Error: Duplicate entry 'devuser' for key 2: INSERT INTO `users`
(`name`, `salt`, `updated_at`, `activated_at`, `crypted_password`,
`remember_token_expires_at`, `activation_code`, `password_reset_code`,
`enabled`, `invitation_id`, `user_type`, `remember_token`,
`identity_url`, `login`, `email`, `created_at`, `invitation_limit`)
VALUES('', '202e1d83b21f9d11b58926811f2b00af5e06da5e', '2009-09-18
01:11:57', NULL, 'faed49f6e2a53904ed62ca98399036e4ceacda39', NULL,
'2c9c7129ba82cfdf7c27e06c3f240ac6a20bc0d0', NULL, 1, NULL, 'SiteUser',
NULL, NULL, 'devuser', NULL, '2009-09-18 01:11:57', 5)

The database has the fields invitation_id and invitation_limit.

Thanks for your help,

Kevin

If this is your dev environment I would drop the database and just do
a clean new rake db:migrate. It's trying to insert the user devuser
that I'm assuming is already in the database or your migration files
tries to insert the user twice... hard to say without the full --trace
output from the command...

Try to drop the db and re-run the migration that would be what I would
do..

Would deleting the user through phpmyadmin be the best way of dropping
the database or do I need to delete the database file altogether?

@Kevin. Did you use rake db:migrate to build your database? I think
hemidull was recommending to drop the schema and redo it. But if you
are building your database externally, then the error shown above
means that the table doesn't exist. If table does exist, it means
your database.yml configuration file is pointing to the wrong schema.

@Mukund To answer your question:
Yes, I used db:migrate to build the database, then I used phpmyadmin
to see what the result was, I'm new to rails programming and thought
it would be useful to examine the result.

I think I have the connection to the database correct, the problem
appears (to me) to be in the setup before I migrate.

I'm doing the restful_authentication with all the bells & whistles
tutorial. I started over again to go from the beginning. When I get to
the migration I get an error, here's the initial error and the full
trace:

ERROR: