Connecting to a mysql server

wlangstroth edited this page Jan 31, 2011 · 1 revision

There are two methods to connect to a mysql server. The first is with an address and port. The second is a socket file. Both methods are talked about below. ##Address and Port

var Client = require('mysql').Client,
    client = new Client();
    client.user = 'root'; 
    client.password = 'root';
    client.host='mysqlserver.com'; //only needed if your mysql server isn't on your localhost
    client.port='5673'; //only needed if your mysql port isn't 3306

    client.connect();

##Socket File To connect a socket file you merely change the port to the file location.

var Client = require('mysql').Client,
    client = new Client();
    client.user = 'root';
    client.password = 'root';
    client.port='/tmp/mysql.sock'; //replace this file location if your is different

    client.connect();