我在 NodeJS 中使用 MySQL 时遇到了一个奇怪的问题。当我连接到互联网时,我的 MySQL 数据库可以工作,但是,当我离线时,查询 MySQL 数据库会出现错误。我正在使用 Express 连接。
我的连接:
app.use(
connection( mysql, {
host: dbConfig.host,
user: dbConfig.user,
password: dbConfig.password,
database: dbConfig.database
}, 'pool' )
);
错误消息:
{
[Error: getaddrinfo ENOENT localhost:3306]
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'getaddrinfo',
hostname: 'localhost',
host: 'localhost',
port: 3306,
fatal: true
}
还有:
connection.query(
^
TypeError: Cannot read property 'query' of undefined
最佳答案
很可能您在 /etc/hosts
文件中缺少 localhost
条目。
关于mysql - 为什么我在 NodeJS 中使用 MySQL 时需要连接互联网?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35680753/