Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dev-guide-sample-application-nodejs-mysql2.md (#16089) #16212

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions develop/dev-guide-sample-application-nodejs-mysql2.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ npm install mysql2 dotenv --save
6. 编辑 `.env` 文件,按照如下格式设置连接信息,将占位符 `{}` 替换为从连接对话框中复制的参数值:

```dotenv
TIDB_HOST={host}
TIDB_PORT=4000
TIDB_USER={user}
TIDB_PASSWORD={password}
TIDB_DATABASE=test
TIDB_ENABLE_SSL=true
TIDB_HOST='{host}'
TIDB_PORT='4000'
TIDB_USER='{user}'
TIDB_PASSWORD='{password}'
TIDB_DATABASE='test'
TIDB_ENABLE_SSL='true'
```

> **Note**
Expand Down Expand Up @@ -124,13 +124,13 @@ npm install mysql2 dotenv --save
5. 编辑 `.env` 文件,按照如下格式设置连接信息,将占位符 `{}` 替换为从连接对话框中复制的参数值:

```dotenv
TIDB_HOST={host}
TIDB_PORT=4000
TIDB_USER={user}
TIDB_PASSWORD={password}
TIDB_DATABASE=test
TIDB_ENABLE_SSL=true
TIDB_CA_PATH={downloaded_ssl_ca_path}
TIDB_HOST='{host}'
TIDB_PORT='4000'
TIDB_USER='{user}'
TIDB_PASSWORD='{password}'
TIDB_DATABASE='test'
TIDB_ENABLE_SSL='true'
TIDB_CA_PATH='{downloaded_ssl_ca_path}'
```

> **Note**
Expand All @@ -154,11 +154,11 @@ npm install mysql2 dotenv --save
2. 编辑 `.env` 文件,按照如下格式设置连接信息,将占位符 `{}` 替换为你的 TiDB 集群的连接参数值:

```dotenv
TIDB_HOST={host}
TIDB_PORT=4000
TIDB_USER=root
TIDB_PASSWORD={password}
TIDB_DATABASE=test
TIDB_HOST='{host}'
TIDB_PORT='4000'
TIDB_USER='root'
TIDB_PASSWORD='{password}'
TIDB_DATABASE='test'
```

3. 保存 `.env` 文件。
Expand Down Expand Up @@ -276,8 +276,8 @@ console.log(rsh.affectedRows);

## 注意事项

- 推荐使用[连接池](https://github.com/sidorares/node-mysql2#using-connection-pools)来管理数据库连接,以减少频繁建立和销毁连接所带来的性能开销。
- 为了避免 SQL 注入的风险,推荐使用[预处理语句](https://github.com/sidorares/node-mysql2#using-prepared-statements)执行 SQL。
- 推荐使用[连接池](https://sidorares.github.io/node-mysql2/docs#using-connection-pools)来管理数据库连接,以减少频繁建立和销毁连接所带来的性能开销。
- 为了避免 SQL 注入的风险,推荐使用[预处理语句](https://sidorares.github.io/node-mysql2/docs#using-prepared-statements)执行 SQL。
- 在不涉及大量复杂 SQL 语句的场景下,推荐使用 ORM 框架 (例如:[Sequelize](https://sequelize.org/)、[TypeORM](https://typeorm.io/) 或 [Prisma](https://www.prisma.io/)) 来提升你的开发效率。
- 当你在数据表中使用到 `BIGINT` 和 `DECIMAL` 类型列时,需要开启 Driver 的 `supportBigNumbers: true` 选项。
- 为了避免由于网络原因出现的 `read ECONNRESET` Socket 错误,可以在 Driver 上开启 `enableKeepAlive: true` 选项。(相关 Issue: [sidorares/node-mysql2#683](https://github.com/sidorares/node-mysql2/issues/683))
Expand All @@ -286,4 +286,4 @@ console.log(rsh.affectedRows);

- 关于 node-mysql2 的更多使用方法,可以参考 [node-mysql2 的 GitHub 仓库](https://github.com/sidorares/node-mysql2)。
- 你可以继续阅读开发者文档的其它章节来获取更多 TiDB 应用开发的最佳实践。例如:[插入数据](/develop/dev-guide-insert-data.md),[更新数据](/develop/dev-guide-update-data.md),[删除数据](/develop/dev-guide-delete-data.md),[单表读取](/develop/dev-guide-get-data-from-single-table.md),[事务](/develop/dev-guide-transaction-overview.md),[SQL 性能优化](/develop/dev-guide-optimize-sql-overview.md)等。
- 如果你更倾向于参与课程进行学习,我们也提供专业的 [TiDB 开发者课程](https://cn.pingcap.com/courses-catalog/category/back-end-developer/?utm_source=docs-cn-dev-guide)支持,并在考试后提供相应的[资格认证](https://learn.pingcap.com/learner/certification-center)。
- 如果你更倾向于参与课程进行学习,我们也提供了专业的 [TiDB 开发者课程](https://cn.pingcap.com/courses-catalog/category/back-end-developer/?utm_source=docs-cn-dev-guide)支持,并在考试后提供相应的[资格认证](https://learn.pingcap.com/learner/certification-center)。