59

Is there a Node.JS Driver for MySQL that is commonly used other than node-mysql?

(It seems like there is not much activity with node.js database drivers. Is there a reason for this or is it just because Node.JS is so young?)

Ethan
  • 57,819
  • 63
  • 187
  • 237
Brad Barrows
  • 1,633
  • 1
  • 13
  • 12
  • 62
    Can this please be reopened. While determining which driver is best might be subjective, it is a very good list of drivers, probably the best compilation on the web. Besides, this page ranks first on Google when you search for "node.js mysql". – Milan Babuškov May 29 '12 at 14:04
  • 12
    This is a useful question. Should be reopened. – Ethan Sep 05 '12 at 22:58
  • 11
    Sometimes debate is actually useful. What better way to find out the pros and cons of various options? Please reopen. If this really isn't a good fit for your format, perhaps you should consider expanding the format. – Todd Price Oct 11 '12 at 00:51
  • 3
    Great question. Visitors get to see opinions of experts that hang around on stackoverflow. – Curious2learn Oct 31 '12 at 13:42
  • 4
    Please reopen, this is constructive and is bringing a lot of users in-search of answers. – udjamaflip Dec 09 '12 at 11:20
  • 1
    I'd like to see this one reopened as well. In a lot of cases, these questions fly off the handle, but this one has been particularly constructive. – mikermcneil Apr 07 '13 at 18:09
  • see http://stackoverflow.com/questions/10377722/most-mature-native-node-js-mysql-driver and http://stackoverflow.com/questions/6345090/what-is-the-most-mature-stable-mysql-node-js-module for listings of node mysql modules – Sam Dufel Apr 15 '13 at 17:01
  • No. No it cannot be re-opened. This is a useful post. Why would we ever re-open a question if it helps you? It's our new business model. Also, remember to save up money for our pay wall coming up soon. – suchislife Jan 18 '22 at 14:07

5 Answers5

26

Here are some options:

WasiF
  • 26,101
  • 16
  • 120
  • 128
NullUserException
  • 83,810
  • 28
  • 209
  • 234
13

You can also try out a newer effort known as Node.js DB that aims to provide a common framework for several database engines. It is built with C++ so performance is guaranteed.

Specifically you could use its db-mysql driver for Node.js MySQL support.

Mariano Iglesias
  • 1,877
  • 1
  • 13
  • 4
5

Just look at https://github.com/Sannis/node-mysql-libmysqlclient.

Sannis
  • 150
  • 1
  • 7
5

If you need an ORM for MySQL you might want to check out http://sequelizejs.com :)

sdepold
  • 6,171
  • 2
  • 41
  • 47
3

For connecting to MySQL with node.js, I've had great success using node-odbc

It's also worked flawlessly for connecting to other databases such as IBM's DB2, and it's been surprisingly fast.

This page is particularly useful for configuring ODBC on linux.

After installing with yum install mysql-connector-odbc, my /etc/odbc.ini file looks like this:

[MYSQL]
Description = MySQL ODBC Driver
Driver      = /usr/lib64/libmyodbc3.so

I left out stuff such as server, user, database, port, password etc. so that I can set these from my connection string (I need to connect to multiple databases).

After saving /etc/odbc.ini, it's installed with this command: odbcinst -i -s -l -f /etc/odbc.ini

And here's a code sample for testing it out:

    var odbc = require("odbc");
    var db = new odbc.Database();
    var conn = "dsn=mysql;server=localhost;user=root;database=mydb;port=3306;password=mypwd;command timeout=30000;";
    db.open(conn, function(err) {
        if(err) throw err;
        var params = ['jiy@stackoverflow.com'];
        var qry = "select * users where email = ?";
        db.query(qry, params, function(err, rows, def) {
            if(err) console.log(err);
            console.log(rows);
        });
    });

Or if you wanted to use coffeescript:

    odbc = require "odbc"
    db = new odbc.Database()
    conn = "dsn=mysql;server=localhost;user=root;database=mydb;port=3306;password=mypwd;command timeout=30000;"

    db.open conn, (err) ->
        throw err if err

        qry = "select * from users where email = ?"

        db.query sql, ["jiy@stackoverflow.com"], (err, rows, def) ->
            if err? then console.log err else
            console.log rows
jiy
  • 858
  • 2
  • 9
  • 18