mysql
mysql copied to clipboard
Currently cannot support auth method mismatch!
deno 1.19.2 MySQL Community Server 8.0.28 https://deno.land/x/[email protected] https://deno.land/x/[email protected]/mod.ts 跑起来报错: error: Uncaught (in promise) Error: Currently cannot support auth method mismatch! throw new Error("Currently cannot support auth method mismatch!"); ^ at PoolConnection._connect (https://deno.land/x/[email protected]/src/connection.ts:104:17) at async PoolConnection.connect (https://deno.land/x/[email protected]/src/connection.ts:148:5) at async Client.createConnection (https://deno.land/x/[email protected]/src/client.ts:47:5) at async DeferredStack.creator (https://deno.land/x/[email protected]/src/pool.ts:61:20) at async DeferredStack.pop (https://deno.land/x/[email protected]/src/deferred.ts:35:16) at async ConnectionPool.pop (https://deno.land/x/[email protected]/src/pool.ts:93:14) at async Client.useConnection (https://deno.land/x/[email protected]/src/client.ts:105:24) at async Client.execute (https://deno.land/x/[email protected]/src/client.ts:96:12)
Try running in your mysql instance this query:
ALTER USER 'root'@'%' IDENTIFIED WITH caching_sha2_password BY 'your-root-password';
Basically there are two authentication strategies and this library supports the latest one.
https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html
Perhaps while this gets fixed you could try using https://github.com/sail-sail/mysql2 that supports both.
This is the one that is throwing the exception:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your-root-password';
I search the code and get the following result
export default function auth(
authPluginName: string,
password: string,
seed: Uint8Array,
) {
switch (authPluginName) {
case "mysql_native_password":
return mysqlNativePassword(password, seed);
case "caching_sha2_password":
return cachingSha2Password(password, seed);
default:
throw new Error("Not supported");
}
}
it seems the driver can support mysql_native_password? @sant123
Interesting, I tested again and now is working:
import { Client } from "https://deno.land/x/[email protected]/mod.ts";
const client = await new Client().connect({
hostname: "127.0.0.1",
username: "root",
db: "mydb",
password: "set-your-password",
});
const users = await client.query(`select * from users`);
console.log(users);
create schema mydb;
use mydb;
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`nombre` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `mydb`.`users` (`nombre`) VALUES ('foo');
INSERT INTO `mydb`.`users` (`nombre`) VALUES ('bar');
INSERT INTO `mydb`.`users` (`nombre`) VALUES ('baz');
docker run -e "MYSQL_ROOT_PASSWORD=set-your-password" -p 3306:3306 -d mysql:8.0.28-oracle
deno 1.28.1 (release, x86_64-unknown-linux-gnu) v8 10.9.194.1 typescript 4.8.3
using mysql 8, for me works with mysql_native_password
and fails with caching_sha2_password
.
this is actually aligned with:
- https://github.com/mysqljs/mysql/issues/1959 -> https://github.com/mysqljs/mysql/pull/1962
- https://stackoverflow.com/questions/50373427/node-js-cant-authenticate-to-mysql-8-0
- https://github.com/docker-library/mysql/issues/275#issuecomment-796076279
steps to reproduce
- setup mysql 8
docker run --name mysql -d \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=change-me --restart unless-stopped \
mysql:8
- log in to mysql server
docker exec -it mysql bash
mysql -u root -p
- set
caching_sha2_password
password
ALTER USER 'root'@'%' IDENTIFIED WITH caching_sha2_password BY 'change-me';
- use this script
import { Client } from "https://deno.land/x/[email protected]/mod.ts";
export async function main() {
const mysql_conn = {
host: '0.0.0.0',
port: 3306,
user: 'root',
password: 'change-me',
database: 'mysql'
};
mysql_conn.db = mysql_conn.database;
mysql_conn.hostname = mysql_conn.host;
mysql_conn.username = mysql_conn.user;
const client = await new Client().connect(
mysql_conn,
);
return (await client.execute('SHOW TABLES'));
}
console.log(await main())
actual result
INFO connecting 0.0.0.0:3306
INFO close connection
Uncaught Error: Access denied for user 'root'@'172.17.0.1' (using password: YES)
at PoolConnection.nextPacket (https://deno.land/x/[email protected]/src/connection.ts:216:13)
at async PoolConnection._connect (https://deno.land/x/[email protected]/src/connection.ts:145:23)
at async PoolConnection.connect (https://deno.land/x/[email protected]/src/connection.ts:179:5)
at async Client.createConnection (https://deno.land/x/[email protected]/src/client.ts:47:5)
at async DeferredStack.creator (https://deno.land/x/[email protected]/src/pool.ts:67:20)
at async DeferredStack.pop (https://deno.land/x/[email protected]/src/deferred.ts:35:16)
at async ConnectionPool.pop (https://deno.land/x/[email protected]/src/pool.ts:99:14)
at async Client.useConnection (https://deno.land/x/[email protected]/src/client.ts:105:24)
at async Client.execute (https://deno.land/x/[email protected]/src/client.ts:96:12)
at async main (<anonymous>:15:12)
expected
it runs
workaround
in mysql docker run
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'change-me';
and then re-run the script, it will not throw that error again
I actually just realized that lack of support for caching_sha2_password
is mentioned in todo list in https://deno-mysql.netlify.app/
Support caching_sha2_password auth plugin (mysql8 default)
@manyuanrong are there any plans in nearest future to support it?
@mrl5 The docs site is outdated. It was supported. I guess recent changes broke it😢. Trying fixing...
@mrl5 The docs site is outdated. It was supported. I guess recent changes broke it😢. Trying fixing...
It seems you have fixed it https://github.com/denodrivers/mysql/pull/142. I am curious about the reason for the bug, is it because the encrypt is wrong?