当前位置:网站首页>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
边栏推荐
猜你喜欢
MongoDB
When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
小L的试卷
Face recognition_ recognition
Learn winpwn (2) -- GS protection from scratch
UDS learning notes on fault codes (0x19 and 0x14 services)
Knowledge Q & A based on Apache Jena
Word排版(小计)
[Blue Bridge Cup 2017 preliminary] grid division
Reading BMP file with C language
随机推荐
Base de données Advanced Learning Notes - - SQL statements
SQL time injection
Database advanced learning notes -- SQL statement
L2-006 树的遍历 (25 分)
搞笑漫画:程序员的逻辑
Julia 1.6 1.7 common problem solving
[Kerberos] deeply understand the Kerberos ticket life cycle
[AGC009D]Uninity
Why can't STM32 download the program
About string immutability
AcWing 179.阶乘分解 题解
Software testing and quality learning notes 3 -- white box testing
Solve the problem of installing failed building wheel for pilot
Software I2C based on Hal Library
牛客Novice月赛40
Install mongdb tutorial and redis tutorial under Windows
Software testing - interview question sharing
分布式節點免密登錄
[蓝桥杯2017初赛]方格分割
Neo4j installation tutorial