当前位置:网站首页>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
- [CDH] modify the default port 7180 of cloudera manager in cdh/cdp environment
- 【flink】flink学习
- QT creator custom build process
- [Blue Bridge Cup 2017 preliminary] buns make up
- Machine learning notes week02 convolutional neural network
- 学习问题1:127.0.0.1拒绝了我们的访问
- L2-007 家庭房产 (25 分)
- 02 staff information management after the actual project
- Introduction and use of automatic machine learning framework (flaml, H2O)
猜你喜欢
MySQL and C language connection (vs2019 version)
Software I2C based on Hal Library
Vs2019 desktop app quick start
MySQL与c语言连接(vs2019版)
{一周总结}带你走进js知识的海洋
【flink】flink学习
AcWing 1298. Solution to Cao Chong's pig raising problem
Word排版(小计)
Django running error: error loading mysqldb module solution
[Flink] Flink learning
随机推荐
[MRCTF2020]套娃
yarn安装与使用
[蓝桥杯2020初赛] 平面切分
Introduction and use of automatic machine learning framework (flaml, H2O)
ES6 let and const commands
AI benchmark V5 ranking
L2-004 is this a binary search tree? (25 points)
UDS learning notes on fault codes (0x19 and 0x14 services)
[Kerberos] deeply understand the Kerberos ticket life cycle
wangeditor富文本引用、表格使用问题
【yarn】CDP集群 Yarn配置capacity调度器批量分配
L2-006 tree traversal (25 points)
Wangeditor rich text reference and table usage
Codeforces Round #771 (Div. 2)
QT creator support platform
QT creator test
Password free login of distributed nodes
QT creator runs the Valgrind tool on external applications
解决安装Failed building wheel for pillow
【yarn】Yarn container 日志清理