当前位置:网站首页>nodejs连接Mysql
nodejs连接Mysql
2022-07-06 09:14:00 【进阶日记】
安装mysql驱动
npm install mysql
连接mysql数据库
//导入mysql驱动 const mysql = require("mysql"); // 配置mysql连接信息 const con = mysql.createConnection({ host:"127.0.0.1",//ip地址 user:"数据库账号", password:"数据库密码", port:"3306",//端口号 database:"book"//要连接的数据库名称 }) // 开始连接 con.connect() // 创建sql语句 const sql = "select * from users;" //执行sql语句 con.query(sql,(err,result)=>{ if(err){ console.error(err); return } console.log(result); }) // 关闭连接 con.end()
有兴趣的小伙伴可以结合学习的nodejs知识编写api接口,可以查看https://blog.csdn.net/qq_47824967/article/details/121909375?spm=1001.2014.3001.5501如何编写接口
边栏推荐
- 数据库高级学习笔记--SQL语句
- Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.
- Machine learning notes week02 convolutional neural network
- [NPUCTF2020]ReadlezPHP
- Why can't STM32 download the program
- AcWing 179.阶乘分解 题解
- TCP/IP协议(UDP)
- Rhcsa certification exam exercise (configured on the first host)
- SQL时间注入
- What does usart1 mean
猜你喜欢
Pytorch基础
One click extraction of tables in PDF
QT creator specifies dependencies
Solve the problem of installing failed building wheel for pilot
QT creator specify editor settings
MTCNN人脸检测
学习问题1:127.0.0.1拒绝了我们的访问
Learning question 1:127.0.0.1 refused our visit
Vs2019 first MFC Application
PHP - whether the setting error displays -php xxx When PHP executes, there is no code exception prompt
随机推荐
Record a problem of raspberry pie DNS resolution failure
AcWing 1294.樱花 题解
Learn winpwn (3) -- sEH from scratch
AcWing 1298.曹冲养猪 题解
Ansible practical series I_ introduction
vs2019 第一个MFC应用程序
Codeforces Round #771 (Div. 2)
Kept VRRP script, preemptive delay, VIP unicast details
vs2019 使用向导生成一个MFC应用程序
Tcp/ip protocol (UDP)
Nanny level problem setting tutorial
ES6 Promise 对象
Learning question 1:127.0.0.1 refused our visit
Cookie setting three-day secret free login (run tutorial)
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
UDS learning notes on fault codes (0x19 and 0x14 services)
ES6 let 和 const 命令
安全测试涉及的测试对象
02-项目实战之后台员工信息管理
Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'