What MySQL drivers are available for node.js?

JavascriptMysqlDatabasenode.js

Javascript Problem Overview


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?)

Javascript Solutions


Solution 1 - Javascript

Here are some options:

Solution 2 - Javascript

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.

Solution 3 - Javascript

Solution 4 - Javascript

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

Solution 5 - Javascript

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 = ['[email protected]'];
		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, ["[email protected]"], (err, rows, def) ->
            if err? then console.log err else
            console.log rows

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrad BarrowsView Question on Stackoverflow
Solution 1 - JavascriptNullUserExceptionView Answer on Stackoverflow
Solution 2 - JavascriptMariano IglesiasView Answer on Stackoverflow
Solution 3 - JavascriptSannisView Answer on Stackoverflow
Solution 4 - JavascriptsdepoldView Answer on Stackoverflow
Solution 5 - JavascriptjiyView Answer on Stackoverflow