Node.js MySQL

Node.js-mysql

Can be used in database applications

MySQL database To be able to experiment with the code examples, you should install MySQL on your computer.
You can download the free MySQL database from https://www.mysql.com/downloads/

Install the mysql module


C:UsersYour Name>npm install mysql

Use the mysql module in the application


var mysql = require('mysql');

Create a mysql connection


var mysql = require('mysql');

var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword"
});

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});

Save a file named demo_node_mysql.js

Then run the file

node dem_node_mysql.js 

The result displays

Connected!

Indicates a successful connection

Leave a Comment

Your email address will not be published. Required fields are marked *

中文 EN
🚀

RedGate VPN

免费节点太挤太慢?
升级高速稳定专线

立即体验 →

告别卡顿

RedGate VPN
全球高速节点

免费下载 →
Scroll to Top