Node.js MySQL

Node.js-mysql

可以在数据库应用程序中使用

MySQL数据库 为了能够使用代码示例进行实验,您应该在您的计算机上安装MySQL。
您可以通过https://www.mysql.com/downloads/下载免费的MySQL数据库

安装mysql模块


C:UsersYour Name>npm install mysql

应用中使用mysql模块


var mysql = require('mysql');

创建mysql连接


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!");
});

保存一个命名为demo_node_mysql.js文件

然后运行文件

node dem_node_mysql.js 

结果显示

Connected!

表示成功连接

Leave a Comment

您的邮箱地址不会被公开。 必填项已用 * 标注

🚀

RedGate VPN

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

立即体验 →

告别卡顿

RedGate VPN
全球高速节点

免费下载 →
Scroll to Top