Installing DBSlayer on Mac OS X Snow Leopard
February 2, 2010
DBSlayer is a tool that will wrap your MySQL database with an HTTP REST/JSON API. Here’s how to get it installed on Snow Leopard using Macports. First, make sure you have all the dependencies install via Macports:
$ sudo port install db46
$ sudo port install apr
$ sudo port install apr-util
$ sudo port install mysql5-server
Then, if you try to download the source and install it:
$ cd ~/src
$ wget http://code.nytimes.com/downloads/dbslayer-beta-12.tgz
$ tar xzf
$ cd dbslayer
$ ./configure
$ make
$ make install
You’ll run into this error:
ld: library not found for -ldb-4.6
collect2: ld returned 1 exit status
make[1]: *** [dbslayer] Error 1
make: *** [all-recursive] Error 1
Instead, pass these options to configure:
$ ./configure CFLAGS="-L/opt/local/lib/db46" \
--with-apr-1-config=/opt/local/bin/apr-1-config \
--with-apu-1-config=/opt/local/bin/apu-1-config \
--with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
Now try to install again:
$ make clean
$ make
$ sudo make install
Next, create the config file, which at it’s most basic, should look something like this:
[my_db]
database=my_db
host=localhost
user=root
Now when you start dbslayer, make sure to give it the full path to the config file:
$ dbslayer -c ~/stuff/my_db.cnf -s my_db
dbslayer starts in the background, so to restart it, you have to find the process and kill it manually. It also doesn’t say whether it worked or not, it just backgrounds with no output. Here’s a little Ruby script to try it out:
require 'open-uri'
require 'rubygems'
require 'json'
require 'pp'
def query_url(sql)
query_hash = { "SQL" => sql }
url_args = URI.encode(query_hash.to_json)
"http://localhost:9090/db?#{url_args}"
end
def exec_query(sql)
url = query_url(sql)
open(url) do |f|
yield JSON.parse(f.read)
end
end
exec_query "select * from stuff limit 1" do |res|
pp res
end
Comments
1.
Macports makes everything hard.
Other than that I can see some utility in this. Or you could just use dbi or jdbc which would most likely be way faster.
2.
Hi Paul,
Thank you for this guide for setting up DBSlayer on OS X. I've got 10.6 on a Mac Pro and have tried setting up DBSlayer two ways: the traditional way by downloading and installing all the dependencies myself, and the second time around I tried Macports.
Both times however I get the following error printed out at the "end" of the make process;
make[1]: Nothing to be done for `all-am'.
I set up the configuration process with all the options you supplied, and by all appearances the config process completes successfully. Attempting to run "make install" after the error in "make" just spits out a bunch of errors, so I imagine that squashing the original error above is the key to getting this set up successfully.
I also attempted to install beta-10 of DBSlayer with the same problem. After a little bit of research it looks like that error above is a little too generic to pinpoint the problem, however I'm a noob when it comes to UNIX work so I don't know where to start. If you could point me in the right direction I would be much obliged. Additionally, if it would help to see the full output from the make process, I'd be happy to supply that.
Thanks for your help!
3.
Whoops, what I originally thought was a problem with make turned out to be a non-issue -- I had to do some modifications to get make install work, but now everything is running perfectly and I've got node.js interacting with my MySQL DB via DBSlayer. This is amazing! Cheers~
Comments Disabled