如何监视节点中的mysql连接状态?

时间:2019-10-05 17:42:21

标签: mysql node.js

这是来自https://www.npmjs.com/package/mysql

html {
  scroll-behavior: smooth;
  ;
}

body {
  background-color: #FBEEC1;
  margin: 0;
  padding: 0;
  text-align: center;
}

#header {
  background-image: url(tempbackground.jpg);
  width: 100%;
  height: 100%;
  background-position: center center;
  background-size: contain;
  background-repeat: no-repeat;
  position: absolute;
}

#title-text {
  position: absolute;
  width: 500px;
  height: 250px;
  top: 50%;
  left: 50%;
  margin-left: -250px;
  /* divide each margin in 1/2 */
  margin-top: -125px;
}

​ .body-text {
  display: none;
  /*This will be enables after scrolling with a scroll animation */
  color: #BC986A;
  width: 100%;
}

.text-width {
  margin: 0 auto;
  width: 50%;
}

.font-title {
  font-family: "Times New Roman", Times, serif;
}

.font-body {
  font-family: Arial, Helvetica, sans-serif;
}

有2个部分使我感到困惑,

  1. connection.connect()是否建立真正的连接?我看到它正在检查错误。但是,如果一切正常,会发生什么,但是5分钟后我关闭mysql服务器,如何监视状态pls? 即使对于池事件,我也看不到断开连接事件。

  2. 对于上面的代码,是否有用于connection.connect()的异步/等待版本?

谢谢!

1 个答案:

答案 0 :(得分:1)

connection.connect是同步的,您可以在连接后使用它。要处理连接错误,您可以使用:

import sys
print ('Running in colab:', 'google.colab' in sys.modules)

通过node-mysql read me

解释一切