var mysql = require (' mysql '); var connection = Mysql.createconnection ({ host : ' localhost ', user : ' Root ', password: ' 123456 ', database: ' Test '}); Connection.connect (); Connection.query (' SELECT 1 + 1 as solution ', function (Error, results, fields) { if (error) throw error; Console.log (' The solution is: ', results[0].solution);});
Parameters |
Description |
Host |
Host address (default: localhost) |
User |
User name |
Password |
Password |
Port |
Port number (default: 3306) |
Database |
Database name |
CharSet |
Connection character Set (default: ' Utf8_general_ci ', note that character set letters are capitalized) |
LocalAddress |
This IP is used for TCP connections (optional) |
Socketpath |
Connect to a UNIX domain path that is ignored when host and Port are used |
TimeZone |
Time zone (default: ' Local ') |
ConnectTimeout |
Connection Timeout (default: No Limit; units: milliseconds) |
Stringifyobjects |
Whether the object is serialized |
Typecast |
Whether to convert column values to local JavaScript type values (default: TRUE) |
Queryformat |
Custom query statement formatting methods |
Supportbignumbers |
This option is required when the database supports bigint or decimal type columns, which is True (default: false) |
Bignumberstrings |
Supportbignumbers and bignumberstrings enable force bigint or decimal columns to be returned as JavaScript string types (default: false) |
Datestrings |
Force the Timestamp,datetime,data type to be returned as a string type instead of a JavaScript date type (default: false) |
Debug |
Turn on debug (default: false) |
Multiplestatements |
Do you want to have multiple MySQL statements in a query (default: false) |
Flags |
Used to modify connection flags |
Qs. |
Use the SSL parameter (one to the crypto.createcredenitals parameter format) or a string that contains the SSL profile name, currently only bundled with Amazon RDS configuration files |
About node. js