pool.js 772 B

12345678910111213141516171819202122232425
  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. port: databseConfig.port,//端口
  17. user: databseConfig.user, //用户
  18. password: databseConfig.password, // 密码
  19. database: databseConfig.database // 数据库名称
  20. }); // 创建连接池对象
  21. module.exports = pool;