我正在尝试将我的 NodeJs 应用程序与 mysql 数据库连接,但由于某种原因它没有连接。
我确实像这样安装了 mysql npm(在命令行中输入):
npm install mysql
Run Code Online (Sandbox Code Playgroud)
安装 mysql npm 后,我创建了一个 index.js 文件,并在该文件中尝试与我的数据库建立连接。
这是我的 index.js 文件中与 mysql 建立连接的代码:
const mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
port : '3306',
password : 'test12310',
database : 'fys'
});
connection.connect((err) => {
if(!err)
console.log('Database is geconnect!');
else
console.log('Database connectie niet gelukt! : '+ JSON.stringify(err, undefined,2));
});
Run Code Online (Sandbox Code Playgroud)
然后我尝试运行代码,看看与 mysql 的连接是否有效。我在命令行中输入:
node index.js
Run Code Online (Sandbox Code Playgroud)
这是我在命令提示符中收到的错误消息:
有谁知道我如何修复此错误并在 nodejs 中与我的 mysqldatabase 建立连接?
任何形式的帮助表示赞赏
我正在使用 Symfony Messenger,我想继续在处理程序中发送消息,直到它被发送多次。
我怎样才能跟踪它?
这是到目前为止我的处理程序类的代码:
class RetryTestHandler implements MessageHandlerInterface
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var MessageBusInterface
*/
private $bus;
public function __construct(MessageBusInterface $bus, EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
$this->bus = $bus;
}
public function __invoke(RetryTest $message)
{
// TODO: Keep dispatching message until it has been dispatched 10 times?
$this->bus->dispatch(new RetryTest("This is a test!"), [
new DelayStamp(5000)
]);
}
}
Run Code Online (Sandbox Code Playgroud)