-
Notifications
You must be signed in to change notification settings - Fork 5
The mysql client object
Roland edited this page Sep 16, 2013
·
9 revisions
The client
object is a member of the mysql
object. It represents the entry point for a MySQL client API. The client
object has the following members:
-
version
- readonlystring
property. This can be used to retrieve the version of the client library. -
connect
- method. Opens a new connection to a MySQL server, and returns the correspondingconnection
object.
The following example illustrates the version
property:
mysql> select js('mysql.client.version;');
The connect
method is used to open a connection to MySQL, which is encapsulated in a connection object.
The connect
method takes a single argument of the object type. This argument is used to specify the properties of the connection. If the connect
method succeeds, it returns a connection
object which can then be used to execute queries and retrieve results. If the connect
method fails, it throws an exception.
The properties for the argument to connect
are:
-
host
- string. Specifies the hostname (or IP-address) of the host where the MySQL server you want to connect to resides. Default value:"localhost"
-
user
- string. Specifies the MySQL username for which the connection is to be established. -
password
- string. Specifies the password of the MySQL user for which the connection is to be established. -
schema
- string. the initial default schema or database name to set for the connection. Once the connection is established, the default schema can be changed with aUSE <schema>
statement, but typically a connection operates within one schema, and this is a convenient way to specify it. -
socket
- string. The name of the socket, in case the connection is to use a UNIX socket. -
port
- integer. The port number to use in case of a TCP/IP connection. Default value:3306
The following example illustrates the connect
method:
var connection;
try {
connection = mysql.client.connect({
user: "sakila",
password: "sakila",
schema: "sakila"
});
}
catch (e) {
console.error(e.message);
}