使用明文密码通过 ssl 使用 nodejs 连接到 MariaDB [英] Connecting to MariaDB with nodejs over ssl with clear text password
问题描述
我正在尝试通过 ssl 连接到 mariadb 实例,
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();
ca 是一个证书数组.我收到以下错误.
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
我可以使用 python 和 mysql.connector 连接到数据库.
I am able to connect to the db using python with mysql.connector.
在调试模式下设置后,我可以看到客户端正在尝试使用 mysql_native_password 身份验证.我需要使用 mysql_clear_password.
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.
推荐答案
如果你的服务器支持基于插件的 auth 和 auth 切换请求,你可以试试下面的代码:
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);
}
});
不幸的是,初始身份验证类型始终是 mysql_native
和 node-mysql2(我希望尽快修复此问题),因此您需要在服务器上启用 auth_plugin 和 auth_switch 支持
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
语法
这篇关于使用明文密码通过 ssl 使用 nodejs 连接到 MariaDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!