2017-08-14 3 views
0

mysql_clear_passwordプラグインを使用してMySQLサーバーに接続しようとしています。次のように私はnode-mysql2の接続構成を設定:knexを使用しているのにmysql2を使用していないときに "mysql_clear_password"プラグインエラーが発生しました

const connectionConfig = { 
    host: rwConfig.host, 
    user: rwConfig.user, 
    database: rwConfig.database, 
    ssl: { 
    ca: sslContent 
    }, 
    password 
} 

その後、私は、次の(私が使用参照のリンク:https://github.com/sidorares/node-mysql2/issues/438#issuecomment-255343793)を:追加mysql_clear_passwordプラグインをサポートするとき、私

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 
}; 

Iはconnectionの値として渡さ​​私はnode-mysql2と接続するために使用されるのと同じオブジェクトである:私は、次の構成オブジェクトを使用します。それから私はknex接続を作成:これは私にエラーを与えている理由を私は知らない

{ 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' } 

const rwConnection = knex(knexConfig); 

これ何らかの理由でこのエラーがスローされます。 knexのドキュメント(http://knexjs.org/)では、それは言う:

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

が、私はそれだけで通過設定を渡すとnode-mysql2を使用して接続を行うだろうと思っていることに基づきます。どんな助けもありがとう。

答えて

1

私は問題を見つけ出しました。今すぐ動作します。 Knexはすべての属性をmsyql2クライアントに渡していませんでした。

これは、この問題に遭遇する可能性のある他の人のために私が行ったことです。 knexがmysql2に渡していた設定をnode_modules/knex/lib/dialect/mysql2に変更し、authSwitchHandlerをconfigOptions配列に追加しました。

+0

これはすでにmasterで修正されています(次のバージョンは0.14になります)。しかし、リリースされたかどうかはわかりません。あなたが使っていたknexバージョンは? –

関連する問題