当前位置:网站首页>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如何编写接口
边栏推荐
- Heating data in data lake?
- 项目实战-后台员工信息管理(增删改查登录与退出)
- yarn安装与使用
- Mtcnn face detection
- Install mongdb tutorial and redis tutorial under Windows
- Solution to the practice set of ladder race LV1 (all)
- Double to int precision loss
- Rhcsa certification exam exercise (configured on the first host)
- Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
- JDBC principle
猜你喜欢
Machine learning -- census data analysis
Picture coloring project - deoldify
How to configure flymcu (STM32 serial port download software) is shown in super detail
机器学习笔记-Week02-卷积神经网络
Install mongdb tutorial and redis tutorial under Windows
QT creator create button
一键提取pdf中的表格
自动机器学习框架介绍与使用(flaml、h2o)
QT creator shape
Software testing and quality learning notes 3 -- white box testing
随机推荐
[蓝桥杯2017初赛]包子凑数
Number game
nodejs 详解
一键提取pdf中的表格
库函数--(持续更新)
Classes in C #
{一周总结}带你走进js知识的海洋
vs2019 第一个MFC应用程序
Did you forget to register or load this tag 报错解决方法
Rhcsa certification exam exercise (configured on the first host)
C语言读取BMP文件
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
QT creator shape
AI benchmark V5 ranking
JDBC principle
Heating data in data lake?
MySQL and C language connection (vs2019 version)
Data dictionary in C #
Some notes of MySQL