You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用discord.js开发Discord机器人时数据库连接报错求助

Discord.js 机器人连接 MySQL 数据库报错求助
  • 我正在使用 discord.js 开发 Discord 机器人,尝试连接 MySQL 数据库时触发错误,无法定位问题根源(不确定是 MySQL 安装问题、代码逻辑问题还是连接配置问题)。

我的代码

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const token = process.env['token']
const password = process.env['pw']

const { createConnection } = require('mysql');
const database = createConnection({
  host: 'localhost',
  port: '3306',
  user: 'root',
  password: password,
  database: 'db2',
  charset: 'utf8mb4'
});

database.connect();

错误信息

控制台显示的错误截图:
MySQL连接错误截图

希望能得到大家的排查思路或解决方案。

内容的提问来源于stack exchange,提问作者whats-an-array

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 19:33:29