phpmyadmin正在以下位置的vps上运行http://ip_address:port_number. 当尝试从nodejs应用程序连接时,我收到错误:“连接丢失:服务器关闭了连接”。
下面是代码片段:-
const express = require('express');
// const bodyParser = require('body-parser');
const mysql = require('mysql');
const app = express();
const port = process.env.PORT || 5000;
// MySQL
const connection = mysql.createPool({
connectionLimit : 1000,
connectTimeout : 60 * 60 * 1000,
acquireTimeout : 60 * 60 * 1000,
timeout : 60 * 60 * 1000,
host : 'ip_address',
user : 'root',
password : 'password',
database : 'customers',
port : port_number,
multipleStatements: true
});
// Listen on environment port of 5000
app.listen(port, () => {
console.log(`Listening on ${port}`)
});
// Get all data
app.get('/', (req, res) => {
let sql = `SELECT * FROM customers_data LIMIT 50`;
connection.query(sql, (err, results) => {
if(err) {
console.log('err', err);
return;
}
console.log('connection established: ', results);
});
});
系统:Windows10,mysql版本:2.18.1(最新),nodejs版本:14.17.1
1条答案
按热度按时间nfg76nw01#
尝试这种连接方式,希望它能起作用