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]

On Sep 14, 4:27 am, Kevin M [email protected] wrote:

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:

We are currently in private beta. Please enter your email
address below and we will let know when an invitation becomes
available.


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

On Sep 14, 4:30 am, Frederick C. [email protected]

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

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

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…

@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.

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?

@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:

== SetUpFirstAdminUser: migrating

rake aborted!
An error has occurred, all later migrations canceled:

You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.activated_at=

FULL TRACE:

(in /Users/Me/Sites/RAT2/restful_authentication_tutorial)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== SetUpFirstAdminUser: migrating

rake aborted!
An error has occurred, all later migrations canceled:

Mysql::Error: Duplicate entry ‘userDEV’ 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(’’, ‘1a9bde41a2d6d664d03e32676c479a07f301d2a6’, ‘2009-09-20
16:23:19’, NULL, ‘b984b8c4f7258b854fab69f85c8b2a95116b41c9’, NULL,
‘1194519fe5c980f38f0d8ffd77f2c8b94625af2b’, NULL, 1, NULL, ‘SiteUser’,
NULL, NULL, ‘userDEV’, NULL, ‘2009-09-20 16:23:19’, 5)
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/
rows_logger/init.rb:36:in log' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/connection_adapters/mysql_adapter.rb: 320:inexecute_without_analyzer’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/
footnotes/lib/rails-footnotes/notes/queries_note.rb:104:in
execute_without_query_stats' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activesupport/lib/active_support/core_ext/benchmark.rb:10:inrealtime’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/
footnotes/lib/rails-footnotes/notes/queries_note.rb:104:in
execute_without_query_stats' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/ query_stats/lib/query_stats/recorder.rb:16:inexecute’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activesupport/lib/active_support/core_ext/benchmark.rb:10:in
realtime' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/ query_stats/lib/query_stats/recorder.rb:15:inexecute’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
database_statements.rb:259:in insert_sql' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/connection_adapters/mysql_adapter.rb: 330:ininsert_sql’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
database_statements.rb:44:in insert_without_query_dirty' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/connection_adapters/abstract/ query_cache.rb:18:ininsert’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/base.rb:2902:in
create_without_timestamps' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/timestamp.rb:29:increate_without_callbacks’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/callbacks.rb:266:in create' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/base.rb:2868:increate_or_update_without_callbacks’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/callbacks.rb:250:in create_or_update' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/base.rb:2539:insave_without_validation’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/validations.rb:1009:in
save_without_dirty' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/dirty.rb:79:insave_without_transactions’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/transactions.rb:229:in send' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/transactions.rb:229:inwith_transaction_returning_status’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
database_statements.rb:136:in transaction' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/transactions.rb:182:intransaction’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/transactions.rb:228:in
with_transaction_returning_status' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/transactions.rb:196:insave’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/transactions.rb:208:in
rollback_active_record_state!' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/transactions.rb:196:insave’
./db/migrate//20080806025753_set_up_first_admin_user.rb:9:in
up_without_benchmarks' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:282:insend’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:282:in migrate' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/benchmark.rb:293:inmeasure’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:282:in migrate' (__DELEGATION__):2:insend
(DELEGATION):2:in migrate' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:486:inmigrate’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:562:in call' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:562:inddl_transaction’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:485:in migrate' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:472:ineach’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:472:in migrate' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:400:inup’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:383:in migrate' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ railties/lib/tasks/databases.rake:116 /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
1.8/monitor.rb:242:in synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load’
/usr/bin/rake:19


Here’s my SetupFirstAdminUser file, should I change ‘settings’ in the
user.email line? What goes there?

class SetUpFirstAdminUser < ActiveRecord::Migration
def self.up
#Be sure to change these settings for your initial admin user
user = SiteUser.new
user.login = “userDEV”
user.email = APP_CONFIG[‘settings’][‘[email protected]’]
user.password = “mypassword”
user.password_confirmation = “mypassword”
user.save(false)
role = Role.new
#Admin role name should be “admin” for convenience
role.name = “admin”
role.save
admin_user = SiteUser.find_by_login(“admin”)
admin_role = Role.find_by_name(“admin”)
admin_user.activated_at = Time.now.utc
admin_user.roles << admin_role
admin_user.save(false)
end

def self.down
admin_user = User.find_by_login(“admin”)
admin_role = Role.find_by_name(“admin”)
admin_user.roles = []
admin_user.save
admin_user.destroy
admin_role.destroy
end
end