pool.js 734 B

123456789101112131415161718192021222324
  1. /*
  2. * @Description: 全局mysql连接
  3. * @Autor: kindring
  4. * @Date: 2021-12-14 11:12:13
  5. * @LastEditors: kindring
  6. * @LastEditTime: 2021-12-15 14:34:31
  7. * @LastDescript:
  8. */
  9. const mysql = require('mysql2');
  10. const databseConfig = require('../configs/database.json'); //数据库连接的配置文件
  11. //作用
  12. //导出全局连接池对象,使其可以统一使用此连接池操作数据库
  13. const pool = mysql.createPool({
  14. connectionLimit: databseConfig.connectionLimit || 100, //连接限制
  15. host: databseConfig.host, //地址
  16. user: databseConfig.user, //用户
  17. password: databseConfig.password, // 密码
  18. database: databseConfig.database // 数据库名称
  19. }); // 创建连接池对象
  20. module.exports = pool;