问题
I am trying to connect to mariadb instance over ssl,
var mysql = require('mysql');
var conn = mysql.createConnection({
user: 'user',
password: 'password',
debug: true,
port: '3306',
host: "host",
ssl: {
"ca": ca
}
});
conn.connect();
the ca is an array of cerificates. I am getting the following error.
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MariaDB client
I am able to connect to the db using python with mysql.connector.
After setting it on debug mode, I can see the client is trying to use mysql_native_password authentication. I need to use mysql_clear_password.
回答1:
if your server supports plugin based auth and auth switch request, you can try following code:
var mysql = require('mysql2');
var conn = mysql.createConnection({
user: 'user',
password: 'password',
debug: true,
port: '3306',
host: "host",
ssl: {
"ca": ca
},
authSwitchHandler = (data, cb) => {
if (data.pluginName === 'mysql_clear_password') {
// https://dev.mysql.com/doc/internals/en/clear-text-authentication.html
var password = 'password\0';
var buffer = Buffer.from(password);
cb(null, buffer);
}
});
unfortunately initial auth type is always mysql_native
with node-mysql2 ( I hope to fix this soon ), so you need both auth_plugin and auth_switch support enabled on server
来源:https://stackoverflow.com/questions/43448563/connecting-to-mariadb-with-nodejs-over-ssl-with-clear-text-password