首先我要说的是,我是一个 javascript 初学者。我正在尝试阅读并学习它。我有一个由 GoDaddy 托管的 MySQL 数据库,并尝试使用不和谐机器人连接到它。下面是代码:
const Discord = require('discord.js');
const client = new Discord.Client();
var mysql = require('mysql');
var con = mysql.createConnection({
host : 'redacted',
port : 'redacted'
user : 'redacted',
password : 'redacted',
database : 'redacted'
});
con.connect(error => {
if(error) throw error;
msg.channel.send("Connection to database successful!");
});
client.login('redacted');
当我运行nodeindex.js时,错误是:
user : 'redacted',
^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
我不明白为什么“用户”是一个意外的标识符。谁能引导我走向正确的方向?
感谢您的宝贵时间。
最佳答案
您在编辑端口后省略了逗号。
关于mysql - 尝试连接mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55305032/