我試圖使用mysql_clear_password
插件連接到MySQL服務器。我建立連接配置node-mysql2
如下:使用knex時出現「mysql_clear_password」插件錯誤,但使用mysql2時出現錯誤
const connectionConfig = {
host: rwConfig.host,
user: rwConfig.user,
database: rwConfig.database,
ssl: {
ca: sslContent
},
password
}
然後以支持mysql_clear_password
插件我添加下述(i所使用的參考的鏈接:https://github.com/sidorares/node-mysql2/issues/438#issuecomment-255343793):
connectionConfig.authSwitchHandler = (data, cb) => {
console.log('In auth switch handler');
if (data.pluginName === 'mysql_clear_password') {
console.log(data);
console.log(data.pluginData.toString('utf8'));
console.log('In mysql clear password');
var tmppassword = connectionConfig.password + '\0';
var buffer = Buffer.from(tmppassword, 'base64');
cb(null, buffer);
}
};
這工作我當嘗試連接到我的數據庫。
現在我嘗試使用knexjs做類似的事情。我用下面的配置對象:
const knexConfig = {
client: 'mysql2',
connection: connectionConfig,
pool: {
min: 0,
max: 20
},
acquireConnectionTimeout: 10000
};
我通過在作爲值用於connection
的是我用於與node-mysql2
連接相同的對象。然後,我創建了一個knex連接:
const rwConnection = knex(knexConfig);
這出於某種原因引發此錯誤:
{ Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Packet.asError (node_modules/mysql2/lib/packets/packet.js:703:13)
at ClientHandshake.Command.execute (node_modules/mysql2/lib/commands/command.js:28:22)
at Connection.handlePacket (node_modules/mysql2/lib/connection.js:515:28)
at PacketParser.onPacket (node_modules/mysql2/lib/connection.js:94:16)
at PacketParser.executeStart (node_modules/mysql2/lib/packet_parser.js:77:14)
at TLSSocket.<anonymous> (node_modules/mysql2/lib/connection.js:386:31)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at TLSSocket.Readable.push (_stream_readable.js:134:10)
at TLSWrap.onread (net.js:547:20)
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlState: '#08004' }
我不知道爲什麼這是給我的錯誤。在knex文檔(http://knexjs.org/)它說:根據我以爲它只是通過傳遞配置,並使用node-mysql2
連接
The connection options are passed directly to the appropriate database client to create the connection, and may be either an object, or a connection string
。任何幫助,將不勝感激。
這已經固定在master(下一個版本將是0.14),但我不記得它是否已經發布。你正在使用哪個版本? –