node-mysql2: Access Denied after database restart (but granted after login via CLI)
Hey there!
I’ve found what it seems to be a strange bug in the authentication with the database. Whenever the database server is restarted, I am getting an access denied error like this one:
error: Uncaught (in promise) Error: Access denied for user 'my_username'@'127.0.0.1' (using password: YES)
at Packet.asError (file:///home/my_username/.cache/deno/npm/registry.npmjs.org/mysql2/3.9.7/lib/packets/packet.js:728:17)
at ClientHandshake.execute (file:///home/my_username/.cache/deno/npm/registry.npmjs.org/mysql2/3.9.7/lib/commands/command.js:29:26)
at Connection.handlePacket (file:///home/my_username/.cache/deno/npm/registry.npmjs.org/mysql2/3.9.7/lib/connection.js:481:34)
at PacketParser.onPacket (file:///home/my_username/.cache/deno/npm/registry.npmjs.org/mysql2/3.9.7/lib/connection.js:97:12)
at PacketParser.executeStart (file:///home/my_username/.cache/deno/npm/registry.npmjs.org/mysql2/3.9.7/lib/packet_parser.js:75:16)
at Socket.<anonymous> (file:///home/my_username/.cache/deno/npm/registry.npmjs.org/mysql2/3.9.7/lib/connection.js:104:25)
at Socket.emit (ext:deno_node/_stream.mjs:1851:9)
at addChunk (ext:deno_node/_stream.mjs:2873:16)
at readableAddChunk (ext:deno_node/_stream.mjs:2852:13)
at Socket.Readable.push (ext:deno_node/_stream.mjs:2791:14)
The user has the permissions to login from anywhere (‘%’) and is using the new caching_sha2_password, as I was tired of the deprecation warnings logs in the database about the mysql_native_password plugin.
My workarround at this moment is the most weird part. If I login to the database with the same credentials using the mysql CLI, I got not error at all, and afterwards the application can also login without getting any more errors until the next database restart.
I’ve been researching a lot in the last day about this issue but can’t find any answer or permanent solution. Anyone else has run into the same issue and can give me some guidance? If you need more information let me know.
Other information
MySQL Version: 8.0.36 Mysql2 version: 3.9.7
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (15 by maintainers)
@pvillaverde fix is published as v3.9.8
Thanks for your help @pvillaverde ! I’ll try to get deno ci running and then publish the fix
Never mind, for some reason the Deno script was using the local node_modules from the NodeJS test instead of the one installed with Deno. It’s working! Great Job, thanks!!
@pvillaverde got it working with deno 1.43.2 by adding
key.padding = 4;beforecrypto.publicEncryptherehttps://github.com/sidorares/node-mysql2/blob/8b5f6911b69b766a3732fa160049d263460da74b/lib/auth_plugins/caching_sha2_password.js#L39
I guess default padding is different between deno and node
maybe related: https://github.com/nodejs/help/issues/1093