我们应该可以换一种创建连接的方法试试。我觉得问题应该是:应用创建以后,创建一个数据连接,这个连接一段时间不用就断开了,这样如果再用这个连接执行 sql 就会报错。
Connection {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
config:
ConnectionConfig {
isServer: undefined,
stream: undefined,
host: 'localhost',
port: 3306,
localAddress: undefined,
socketPath: undefined,
user: 'root',
password: 'PASSWORD',
passwordSha1: undefined,
database: 'nid_node',
connectTimeout: 10000,
insecureAuth: false,
supportBigNumbers: false,
bigNumberStrings: false,
decimalNumbers: false,
dateStrings: false,
debug: undefined,
trace: true,
stringifyObjects: false,
enableKeepAlive: false,
keepAliveInitialDelay: 0,
timezone: 'local',
queryFormat: undefined,
pool: undefined,
ssl: false,
multipleStatements: false,
rowsAsArray: false,
namedPlaceholders: false,
nestTables: undefined,
typeCast: true,
maxPacketSize: 0,
charsetNumber: 224,
compress: false,
authPlugins: undefined,
authSwitchHandler: undefined,
clientFlags: 11203535,
connectAttributes: undefined,
maxPreparedStatements: 16000 },
stream:
Socket {
connecting: true,
_hadError: false,
_parent: null,
_host: 'localhost',
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: true,
paused: false,
emitClose: false,
autoDestroy: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
_events:
[Object: null prototype] {
end: [Function: onReadableStreamEnd],
error: [Function: bound _handleNetworkError],
data: [Function],
close: [Function] },
_eventsCount: 4,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: false,
autoDestroy: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
[Symbol(asyncId)]: 4,
[Symbol(kHandle)]:
TCP {
reading: false,
onconnection: null,
[Symbol(owner)]: [Circular] },
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0 },
_internalId: 0,
_commands:
Denque {
_head: 0,
_tail: 0,
_capacityMask: 3,
_list: [ <4 empty items> ] },
_command:
ClientHandshake {
_events:
[Object: null prototype] { end: [Function], error: [Function] },
_eventsCount: 2,
_maxListeners: undefined,
next: [Function: handshakeInit],
handshake: null,
clientFlags: 11203535 },
_paused: false,
_paused_packets:
Denque {
_head: 0,
_tail: 0,
_capacityMask: 3,
_list: [ <4 empty items> ] },
_statements:
LRUCache {
[Symbol(max)]: 16000,
[Symbol(lengthCalculator)]: [Function: naiveLength],
[Symbol(allowStale)]: false,
[Symbol(maxAge)]: 0,
[Symbol(dispose)]: [Function: dispose],
[Symbol(noDisposeOnSet)]: false,
[Symbol(updateAgeOnGet)]: false,
[Symbol(cache)]: Map {},
[Symbol(lruList)]: Yallist { tail: null, head: null, length: 0 },
[Symbol(length)]: 0 },
serverCapabilityFlags: 0,
authorized: false,
sequenceId: 0,
compressedSequenceId: 0,
threadId: null,
_handshakePacket: null,
_fatalError: null,
_protocolError: null,
_outOfOrderPackets: [],
clientEncoding: 'utf8',
packetParser:
PacketParser {
buffer: [],
bufferLength: 0,
packetHeaderLength: 4,
headerLen: 0,
length: 0,
largePacketParts: [],
firstPacketSequenceId: 0,
onPacket: [Function],
execute: [Function: executeStart],
_flushLargePacket: [Function: _flushLargePacket4] },
serverEncoding: 'utf8',
connectTimeout:
Timeout {
_idleTimeout: 10000,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 549,
_onTimeout: [Function: bound _handleTimeoutError],
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(refed)]: true,
[Symbol(asyncId)]: 8,
[Symbol(triggerId)]: 1 } }