来自神光的《Nest 通关秘籍》
创建项目
1 2 3
| npx typeorm@latest init --name typeorm-all-feature --database mysql cd typeorm-all-feature npm install --save mysql2
|
然后改下用户名密码数据库,把连接 msyql 的驱动包改为 mysql2,并修改加密密码的方式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import "reflect-metadata" import { DataSource } from "typeorm" import { User } from "./entity/User"
export const AppDataSource = new DataSource({ type: "mysql", host: "localhost", port: 3306, username: "root", password: "guang", database: "practice", synchronize: true, logging: true, entities: [User], migrations: [], subscribers: [], poolSize: 10, connectorPackage: 'mysql2', extra: { authPlugin: 'sha256_password', } })
|
connectorPackage要修改成mysql2