2

I've long been a user of sqlite3 (with rails) and I never got a chance to try mysql, until now. I need to configure to use it along with Datamapper. Following the tutorial I need to install the dm-mysql-adapter using this command:

sudo apt-get install libmysqlclient-dev 

My .rb file contains the following code:

require 'data_mapper' DataMapper.setup(:default, "mysql://user:password@hostname/database") class Post include DataMapper::Resource property :id , Serial property :title , String property :body , Text property :created_at , DateTime end 

Which doesn't run and gives me the following error:

in `require': no such file to load -- dm-mysql-adapter (LoadError) 

I believe, I need to set up a username and password to get mysql up and running and then establish a connection with Datamapper. Can someone please guide me.

Thanks a lot!

3
  • Nope, you'll need to install dm-mysql-adapter via gem. Commented Mar 24, 2012 at 16:50
  • Yup I did that and I included it in my code. The code ran fine but how can I see if a database was successfully created (like one can see a development.db file using sqlite with rails) Commented Mar 24, 2012 at 16:56
  • The existence of development.db doesn't tell you anything. Grab any mysql client (the simplest one is probably mysql on the command line) and do some introspection. Commented Mar 24, 2012 at 17:11

2 Answers 2

6

What you're probably getting wrong is that you haven't installed your mysql server. Do this:

sudo apt-get install mysql-server 

During the installation, you'll be prompted for a password. Now your mysql server should be running. Use this command to check if it is running:

sudo netstat -tap | grep mysql 

Now you need to login as a user and create a database which you'll use in your datamapper

mysql -u root -p 

and when logged in, write

$ create database my_db; 

Now in put these values in the datamapper setup call for eg.

DataMapper.setup(:default, "mysql://root:password@localhost/my_db") 

Hope that helps ;)

Sign up to request clarification or add additional context in comments.

Comments

1

try installing this gem

gem install dm-mysql-adapter 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.