3
votes

I have a database file (name.sql) that was sent to me that I am supposed to connect to a rails app locally hosted on my mac, that I downloaded (forked?) from github. How do I set up my database.yml file to connect with the sql files.

2

2 Answers

5
votes

You can't connect a Rails application directly to a SQL file. The Rails application gets its data from a database server and you import the contents of the SQL file into a database hosted by the server.

You can download a DMG archive which will install MySQL Community Server on your Mac from http://dev.mysql.com/downloads/mysql/#downloads

That download also includes a handy Preference Pane for starting and stopping the server.

Once you have MySQL up and running then you should set a password for the root user (i.e. the database system administrator) using

mysqladmin -u root password "secret"

—Obviously replace secret with the real password you want to use.

Then you can set up the database.yml file for the Rails application. For an application named app it would look like this:

development:
  adapter: mysql
  database: app_development
  username: root
  password: secret
  host: localhost

test:
  adapter: mysql
  database: app_test
  username: root
  password: secret
  host: localhost

production:
  adapter: mysql
  database: app_production
  username: root
  password: secret
  host: localhost

Note that typically in production you'd create a separate limited privilege database user account for the Rails application to connect to MySQL with, but for development on your local machine the root account is fine.

After this step you can run rake db:create from the root of the Rails application within the Terminal. This command will create the app_development database in MySQL (rake db:create:all creates the test and production databases too). Finally, you can import your SQL file by entering the following command in the Terminal:

mysql -u root -p app_development < path/to/file/name.sql

You will be prompted for the MySQL root password. Replace path/to/file with the full path to the SQL file if it's not within the Terminal's current directory. For example, use ~/Desktop/name.sql if it's on your desktop.

0
votes

Probably easiest: you need to run a database server on your mac. Then import your data into your database server.

Tutorials on installing rails on a mac will also talk about how to install the local database server and setting up the database.yml file