允许任意地址访问 MySQL 数据库 adonis 的新用户

问题

ayear@DESKTOP-GPCA3B0:~/AdonisJS$ node ace.js migration:run
[ error ] Host 'DESKTOP-GPCA3B0' is not allowed to connect to this MySQL server
          at Packet.asError (/home/ayear/AdonisJS/node_modules/.pnpm/mysql2@3.9.4/node_modules/mysql2/lib/packets/packet.js:728:17)
          at ClientHandshake.execute (/home/ayear/AdonisJS/node_modules/.pnpm/mysql2@3.9.4/node_modules/mysql2/lib/commands/command.js:29:26)
          at Connection.handlePacket (/home/ayear/AdonisJS/node_modules/.pnpm/mysql2@3.9.4/node_modules/mysql2/lib/connection.js:481:34)
          at PacketParser.onPacket (/home/ayear/AdonisJS/node_modules/.pnpm/mysql2@3.9.4/node_modules/mysql2/lib/connection.js:97:12)
          at PacketParser.executeStart (/home/ayear/AdonisJS/node_modules/.pnpm/mysql2@3.9.4/node_modules/mysql2/lib/packet_parser.js:75:16)
          at Socket.<anonymous> (/home/ayear/AdonisJS/node_modules/.pnpm/mysql2@3.9.4/node_modules/mysql2/lib/connection.js:104:25)
          at Socket.emit (node:events:518:28)
          at addChunk (node:internal/streams/readable:559:12)
          at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
          at Readable.push (node:internal/streams/readable:390:5)

因为用户 root 不允许主机 DESKTOP-GPCA3B0 访问。

解决方法

创建一个用户并允许任意地址访问 % 表示任意

adonis.* 表示数据库 adonis

MySQL 版本 8.0

mysql> CREATE USER 'myUserName'@'%' IDENTIFIED BY 'myPassword';
Query OK, 0 rows affected (0.03 sec)

mysql> GRANT ALL PRIVILEGES ON adonis.* TO 'myUserName'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
posted @ 2024-04-13 15:13  mcayear  阅读(29)  评论(0)    收藏  举报