In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Preface
The mysql module (project address is https://github.com/mysqljs/mysql) is an open source, JavaScript-written MySQL driver that can operate MySQL in Node.js applications. However, in the process of use, there is a "ER_NOT_SUPPORTED_AUTH_MODE" problem.
This paper introduces the causes and solutions of the problem.
Error message
When I try to connect to MySQL 8 using the mysql module, the following error message appears:
D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ index.js:17throw error; ^ Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server Consider upgrading MySQL clientat Handshake.Sequence._packetToError (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ lib\ protocol\ sequences\ Sequence.js:47:14) at Handshake.ErrorPacket (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ lib\ protocol\ sequences\ Handshake.js:123:18) at Protocol._parsePacket (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ lib Protocol\ Protocol.js:291:23) at Parser._parsePacket (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ lib\ protocol\ Parser.js:433:10) at Parser.write (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ lib\ protocol\ Parser.js:43:10) at Protocol.write (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ Lib\ protocol\ Protocol.js:38:16) at Socket. (d:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ lib\ Connection.js:91:28) at Socket. (d:\ workspaceGithub\ nodejs-book-samples\ samples\ node_modules\ mysql\ lib\ Connection.js:525:10) at Socket.emit (events.js:196:13) at addChunk (_ stream_readable.js:290:12)-at Protocol._enqueue (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ lib\ protocol\ Protocol.js:144: 48) at Protocol.handshake (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ lib\ protocol\ Protocol.js:51:23) at Connection.connect (D:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ node_modules\ mysql\ lib\ Connection.js:119:18) at Object. (d:\ workspaceGithub\ nodejs-book-samples\ samples\ mysql-demo\ index.js:12:12) at Module._compile (internal/modules/cjs/loader.js:759:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10) at Module.load (internal/modules/cjs/loader.js:628:32) at Function.Module._load (internal/modules/cjs/loader.js:555:12) at Function.Module.runMain (internal) / modules/cjs/loader.js:826:10) at internal/main/run_main_module.js:17:11
Cause of error
The reason for this error is that currently, the latest mysql module does not fully support MySQL 8's "caching_sha2_password" encryption, while "caching_sha2_password" is the default encryption in MySQL 8. Therefore, the following command is that "caching_sha2_password" encryption has been used by default, and the account and password cannot be used in the mysql module.
Mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY' 123456 query OK, 0 rows affected (0.12 sec)
Solution method
The solution is to change the password of user root and specify the encryption method that the mysql module can support:
Mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY' 123456 query OK, 0 rows affected (0.12 sec)
The above statement shows that the encryption method using "mysql_native_password" is specified. This approach is supported in the mysql module.
If you run the application here, you can see the following console output information:
$node index.jsThe result is: RowDataPacket {user_id: 1, username: 'Lao Wei'}
Where "RowDataPacket {user_id: 1, username: 'Lao Wei'}" is the result of the database query.
Source code
Examples of this section can be found in https://github.com/waylau/nodejs-book-samples 's "mysql-demo" application.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.