当前位置:网站首页>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
边栏推荐
- 人脸识别 face_recognition
- Deoldify project problem - omp:error 15:initializing libiomp5md dll,but found libiomp5md. dll already initialized.
- QT creator support platform
- Neo4j installation tutorial
- express框架详解
- Vs2019 desktop app quick start
- [蓝桥杯2017初赛]方格分割
- AI benchmark V5 ranking
- ImportError: libmysqlclient. so. 20: Cannot open shared object file: no such file or directory solution
- AcWing 1298.曹冲养猪 题解
猜你喜欢
C语言读取BMP文件
Machine learning notes week02 convolutional neural network
小L的试卷
保姆级出题教程
第4阶段 Mysql数据库
Valentine's Day flirting with girls to force a small way, one can learn
AI benchmark V5 ranking
{one week summary} take you into the ocean of JS knowledge
{一周总结}带你走进js知识的海洋
Introduction and use of automatic machine learning framework (flaml, H2O)
随机推荐
L2-001 紧急救援 (25 分)
[蓝桥杯2017初赛]方格分割
Codeforces Round #753 (Div. 3)
MongoDB
How to set up voice recognition on the computer with shortcut keys
[Kerberos] deeply understand the Kerberos ticket life cycle
【yarn】Yarn container 日志清理
[yarn] CDP cluster yarn configuration capacity scheduler batch allocation
Nanny level problem setting tutorial
ES6 let and const commands
Mtcnn face detection
PHP - whether the setting error displays -php xxx When PHP executes, there is no code exception prompt
[Flink] Flink learning
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
MySQL与c语言连接(vs2019版)
C语言读取BMP文件
Cookie setting three-day secret free login (run tutorial)
When using lambda to pass parameters in a loop, the parameters are always the same value
Request object and response object analysis
【flink】flink学习