5

I am desperately in need of help from any charitable ruby/rails experts out there. I really want to learn RoR, but I can't get anywhere because every time I get to the stage where I need to connect to the database, something is messed up. Here's what I've got going at the moment.

[ Mac OSX 10.6.6 -- Ruby 1.9.2 -- Rails 3.0.5 -- MySQL 5.5.10 ]

All of these are the latest versions, freshly installed, and running smoothly. I also have rvm installed. All I want to know is how I can set up a new Rails project using a MySQL database and connect to it properly. I have spent countless hours googling around and getting error after error after error.

Can anyone help me out by outlining step by step how I can just get a working rails project connected to a mysql database? If anyone can help me with this I will not only owe you my life, but I will make amazing web and interface designs for you for free and/or collaborate on your next project as a UI designer. I will in addition give you free photoshop/graphics advising for life.

I want to learn rails so so bad, but I am in over my head right now with this file configuration stuff and wasting massive amounts of time. Please help!

Jeff Escalante
  • 3,137
  • 1
  • 21
  • 30
  • 7
    Jeff, we can't help you unless you give us specifics. You need to tell us what you've tried and what errors you're getting. We'd like to help you, but aren't magicians. – ryeguy Mar 20 '11 at 05:25
  • There's no guide around, but this topic might turn itself into one, once you give us enough information to help you solve it. I've been bitten a lot trying to make a Rails setup similar to yours, and I learned a lot, but I can't remember all the issues I went through. So, start posting your troubles and we'll gladly help. – Fábio Batista Mar 20 '11 at 05:41
  • 1
    Have you tried this one? http://cakebaker.42dh.com/2009/03/13/generating-a-rails-project-configured-to-use-mysql/ It's a little old, but deals with Rails 3. – Mason Mar 20 '11 at 07:10

2 Answers2

13

You'll owe me your life!!!! WOW! Seriously, try this:

rails new example -d mysql

config.database.yml created

development:
  adapter: mysql2  
  encoding: utf8
  database: example_development
  pool: 5
  username: root
  password:
  socket: /var/run/mysqld/mysqld.sock

Go into your new project

cd example

Then install gems needed (mysql2)

bundle install

Then create your database

rake db:create

Profit!

If you can't use /var/run/mysqld/mysqld.sock as a pointer to connect to your mysql, then edit it to look like this https://gist.github.com/878434 and customize the port and username/password

Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • Tried doing this, and this was the error I got. Thanks for the steps though! Perhaps someday I will profit... -- rake aborted! dlopen(/Users/Jeff/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/Jeff/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle Reason: image not found - /Users/Jeff/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle /Users/Jeff/Sites/simple_cms/Rakefile:4:in `' – Jeff Escalante Mar 21 '11 at 04:14
  • 1
    It would seem that you're missing libmysqlclient. Is it in Macports? – Mike Yockey Mar 21 '11 at 11:49
  • Try the solution with 9 upvotes on http://stackoverflow.com/questions/4512362/rails-server-fails-to-start-with-mysql2-using-rvm-ruby-1-9-2-p0-on-osx-10-6-5 – Jesse Wolgamott Mar 21 '11 at 12:14
  • Tried this, and got the following error: install_name_tool: can't open file: /Users/Jeff/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle (No such file or directory) – Jeff Escalante Mar 21 '11 at 21:14
  • @Jeff: when you type in "gem which mysql2" do you get anything? you should NOT get "ERROR: Can't find ruby library file or shared library mysql2"... if you do, you need to "bundle install" and confirm "mysql2" is in your Gemfile – Jesse Wolgamott Mar 22 '11 at 00:36
  • I get this when I do the 'gem which' command: /Users/Jeff/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb – Jeff Escalante Mar 22 '11 at 14:40
  • Feels like a mysql install problem.... Try installing with homebrew: http://solutions.treypiepmeier.com/2010/02/28/installing-mysql-on-snow-leopard-using-homebrew/ – Jesse Wolgamott Mar 22 '11 at 14:48
  • Hey Jesse, I tried this and got a chown error. I left a comment for the guy who wrote that post, and he said I should just use the official package installer, which was what I used originally. Hmm... – Jeff Escalante Mar 28 '11 at 16:06
  • Jeff -- all of your problems seem to have to do with your system's inability to install programs and libraries. you can either 1) ask those questions on http://serverfault.com/ or 2) start deleting and removing most everything and starting over with homebrew and not using sudo – Jesse Wolgamott Mar 28 '11 at 17:59
  • @JesseWolgamott Jesse can you tell me how to solve "ERROR: Can't find ruby library file or shared library mysql2" problem, thanks in advanced. – Ishikawa Yoshi May 14 '14 at 08:11
3

Give a look at this post here :http://freddyandersen.wordpress.com/2010/10/03/mysql-5-5-snow-leopard-and-rails/

Surya
  • 15,703
  • 3
  • 51
  • 74