连接到数据库时,使用节点包mysql v2.16.0时出错错误:数据包无序获取:80预期:0

z4bn682m  于 2021-06-17  发布在  Mysql
关注(0)|答案(2)|浏览(419)

版本:
节点>11.4.0
mysql(节点包)>2.16.0
phpmyadmin>4.8.3
mysql>5.7版本
我使用的代码是:

const mysql = require('mysql');

let db = mysql.createConnection({
  host:'hidden',
  port:'hidden',
  user:'hidden',
  password:'hidden',
  database: 'hidden',
  dubug: true
});

sqlfn.createTable('Internal', db, 'test_table', (result, err) => {
  if(err) {console.log(err.stack); return};
  console.log('Create OK: ', result);
});

从函数文件sqlfn:

exports.createTable = (req, db, name, callback) => {
  let query_string = String(`CREATE TABLE ${name} (uid VARCHAR(255), name VARCHAR(255), type VARCHAR(255), data VARCHAR(255), modified VARCHAR(255))`);

  db.query(query_string, (err, result) => {
      if(err) fn.logit(req, 'SQL', 'error', `in <createTable> ${err}`);

      callback(result, err);
  });
};

这是我得到的错误:

错误:数据包顺序错误。在socket处的protocol.write(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\protocol\parser.js:42:19)处的parser.write(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\protocol\protocol.js:38:16)处的get:80预期值:0(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\connection.js:91:28)位于套接字(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\connection.js:502:10)在socket.emit(events.js:189:13)在addchunk(\u stream\u readable.js:288:12)在readableaddchunk(\u stream\u readable.js:269:11)在socket.readable.push(\u stream\u readable.js:224:10)在tcp.onstreamread[as onread](internal/stream\u base\u commons.js:145:17)

f4t66c6m

f4t66c6m1#

我得到了同样的错误,这是因为我没有设置正确的端口,我的数据库是3305而不是默认的3306

t8e9dugd

t8e9dugd2#

在protocol.handshake(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\protocol\protocol.js:144:48)在connection.connect(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\protocol\protocol.js:51:23)在connection.connect(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\connection.js在连接处。\ implyconnect(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\connection.js:453:10)在object.exports.createtable(c:\users\hidden\documents\git\hidden\node\u modules\mysql\lib\connection.js:36:8)在object.query(c:\users\hidden\documents\git\hidden\components\functions\sql.js:36:8)在object.exports(c:\users\hidden\documents\git\hidden\components\controllers\controll\u admin.js:22:7)at module.\u compile(internal/modules/cjs/loader.js:723:30)at object.module.\u extensions..js(internal/modules/cjs/loader.js:734:10)at module.load(internal/modules/cjs/loader.js:620:32)
如果有人知道我可以修复或解决这个问题,我希望得到一些反馈和帮助。
谢谢。:)

相关问题