DBSlayer is a simpler way to proxy mysql.
DBSlayer can be queried via JSON over HTTP, and the responses can be given in either one of the following supported languages : JSON, PHP and Python which makes processing the database results.
Multi-threaded server written in C.
Features :
- Reduce configuration
- Reduce dependencies
- Handle failovers
- Simple load balancing
- Easy to monitor
- Minimal performance overhead
- Work in different configuration scenarios
- Support different programming languages
Installing DBSlayer :
1 2 3 4 5 6 7 |
git clone https://github.com/derekg/dbslayer.git ./configure make make install |
Database URI :
http://machine:port/db?URLENCODED(JSON OBJECT)
http://machine:port/dbform?URLENCODED(HTML FORM)
Parameters :
SQL – SQL to execute
Example Request :
1 |
http://localhost:9090/dbform?SQL=SELECT+name+FROM+emp |
Example Response :
1 2 3 4 5 6 7 8 9 |
{'RESULT': {'HEADER': ['name'], 'ROWS' : [['name']], 'TYPES' : ['MYSQL_TYPE_VAR_STRING'], 'SERVER' : 'servername' }} |
Example for python :
1 2 3 4 5 6 7 8 |
import urllib2, urllib, json def dbex(): uri = 'http://localhost:9090/dbform?SQL=%s' data = urllib2.urlopen(uri%urllib.quote('SELECT * FROM market')).read() print json.loads(data) dbex() |
Start dbslayer :
1 |
dbslayer -c /path/dbslayer.conf -s servername |
This starts up a DBSlayer daemon on 9090 (this default port can be changed which acts as a proxy for the backend mysql server. this proxy can be queried via JSON over HTTP).
Stop dbslayer :
1 |
pkill dbslayer |
Other URI/API endpoints :
http://machine:port/stats [Queries per second]
http://machine:port/stats/log [Last 100 requests]
http://machine:port/stats/errors [Last 100 error]
http://machine:port/shutdown [Only from localhost]