当前位置:网站首页>Nodejs connect mysql
Nodejs connect mysql
2022-07-06 11:36:00 【Advanced diary】
install mysql drive
npm install mysql
Connect mysql database
// Import mysql drive const mysql = require("mysql"); // To configure mysql Connection information const con = mysql.createConnection({ host:"127.0.0.1",//ip Address user:" Database account ", password:" Database password ", port:"3306",// Port number database:"book"// The name of the database to connect to }) // Start connecting con.connect() // establish sql sentence const sql = "select * from users;" // perform sql sentence con.query(sql,(err,result)=>{ if(err){ console.error(err); return } console.log(result); }) // Close the connection con.end()
Interested partners can learn together nodejs Knowledge compilation api Interface , You can see https://blog.csdn.net/qq_47824967/article/details/121909375?spm=1001.2014.3001.5501 How to write interfaces
边栏推荐
猜你喜欢
vs2019 使用向导生成一个MFC应用程序
MongoDB
Case analysis of data inconsistency caused by Pt OSC table change
About string immutability
{one week summary} take you into the ocean of JS knowledge
QT creator test
保姆级出题教程
Reading BMP file with C language
Software testing and quality learning notes 3 -- white box testing
[Flink] Flink learning
随机推荐
Double to int precision loss
牛客Novice月赛40
第4阶段 Mysql数据库
Heating data in data lake?
Mysql的索引实现之B树和B+树
Machine learning notes week02 convolutional neural network
Software testing and quality learning notes 3 -- white box testing
4、安装部署Spark(Spark on Yarn模式)
[蓝桥杯2017初赛]方格分割
About string immutability
[CDH] modify the default port 7180 of cloudera manager in cdh/cdp environment
ES6 promise object
分布式节点免密登录
Codeforces Round #771 (Div. 2)
UDS learning notes on fault codes (0x19 and 0x14 services)
Pytoch Foundation
Solution to the practice set of ladder race LV1 (all)
库函数--(持续更新)
[AGC009D]Uninity
AcWing 1298. Solution to Cao Chong's pig raising problem