MySQL
Plugin
MySQL is a NodeJS plugin. You must download NodeJS recommend version fron [official site (https://nodejs.org/en/)\](https://nodejs.org/en/) and install it with `npm install mysql` OK. We installed MySQL. In our index.js write this:
```js var mysql = require('mysql'); ```
So. Functions for working with MySQL:
createConnection
Create information for connection but do not open it.
```js var mysqlc = mysql.createConnection({
host:'127.0.0.1',// host of server
user:'kostya_nad',// MySQL user
password:'MyStrongPassword',// MySQL password
database:'gmgta'// MySQL database
}); ```
connect
Open connection to database
```js mysqlc.connect(function(e) { if(e) {
console.log("Error connecting to the database with error "+e);
} else {
console.log('Database connected!')
} }); ```
end
Close connection to database
```js mysqlc.end(); ```
query
Send a MySQL query to database
```js mysqlc.query("SELECT * FROM `users` WHERE `nickname`=", [], function(e, r) { if(e) { console.log('Error on connection ... '); throw e; } else { console.log('Password is '+r[0].passcode); } }); ```