nodejs 访问mysql数据库超时的bug解决

本文描述了一个关于使用bigint20存储时间戳数据导致MySQL查询性能大幅下降的问题。在实际项目中,采用bigint20类型存储时间戳,在进行多次select between查询后发现MySQL服务器无响应。而将bigint改为普通int类型后,问题得以解决。

实际项目中有一个表格

用了bigint 20 存储了时间戳数据

当用 select between 查询的时候,几十次查询 mysql服务器就没有响应了

具体的表现就是nodejs  http请求可以达到但是没有响应

bigint  修改为普通的int 就能恢复正常

以下是使用Node.js操作MySQL数据库的示例代码: 1.安装mysql模块 ```shell npm install mysql ``` 2.连接MySQL数据库 ```javascript const mysql = require('mysql'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'password', database: 'test' }); connection.connect((err) => { if (err) throw err; console.log('Connected!'); }); ``` 3.创建数据库 ```javascript const mysql = require('mysql'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'password' }); connection.connect((err) => { if (err) throw err; console.log('Connected!'); connection.query('CREATE DATABASE test', (err, result) => { if (err) throw err; console.log('Database created!'); }); }); ``` 4.创建表 ```javascript const mysql = require('mysql'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'password', database: 'test' }); connection.connect((err) => { if (err) throw err; console.log('Connected!'); const sql = 'CREATE TABLE customers (name VARCHAR(255), address VARCHAR(255))'; connection.query(sql, (err, result) => { if (err) throw err; console.log('Table created!'); }); }); ``` 5.插入数据 ```javascript const mysql = require('mysql'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'password', database: 'test' }); connection.connect((err) => { if (err) throw err; console.log('Connected!'); const sql = 'INSERT INTO customers (name, address) VALUES ("Company Inc", "Highway 37")'; connection.query(sql, (err, result) => { if (err) throw err; console.log('1 record inserted'); }); }); ``` 6.查询数据 ```javascript const mysql = require('mysql'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'password', database: 'test' }); connection.connect((err) => { if (err) throw err; console.log('Connected!'); const sql = 'SELECT * FROM customers'; connection.query(sql, (err, result) => { if (err) throw err; console.log(result); }); }); ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值