错误信息
F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\protocol\Parser.js:437
throw err; // Rethrow non-MySQL errors
^
TypeError: Cannot read properties of undefined (reading 'query')
at F:\servicepro\project\routes\database.js:17:16
at Handshake.onConnect (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\Pool.js:58:9)
at Handshake.<anonymous> (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\Connection.js:526:10)
at Handshake._callback (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\Connection.js:488:16)
at Handshake.Sequence.end (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\protocol\sequences\Sequence.js:83:24)
at Handshake.ErrorPacket (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\protocol\sequences\Handshake.js:125:8)
at Protocol._parsePacket (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\protocol\Parser.js:433:10)
at Parser.write (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (F:\servicepro\project\node_modules\_mysql@2.18.1@mysql\lib\protocol\Protocol.js:38:16)
原因
MySQL8.0.4以前MySQL的密码认证插件是mysql_native_password,而现在使用的是caching_sha2_password。
解决方案
-
登录本地数据库
C:\Users\spr-Gz>mysql -u root -p Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 17 Server version: 8.0.30 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456'; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) -
node项目重启