From 44ff1dbee6d835292f9593488cbefee488ae0e52 Mon Sep 17 00:00:00 2001 From: pjmw9izve <2308014474@qq.com> Date: Sun, 6 Oct 2024 11:28:35 +0800 Subject: [PATCH] ADD file via upload --- db.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 db.js diff --git a/db.js b/db.js new file mode 100644 index 0000000..d7b62d8 --- /dev/null +++ b/db.js @@ -0,0 +1,24 @@ +const mysql = require('mysql2/promise'); + +// 创建连接池 +const pool = mysql.createPool({ + host: 'localhost', // 数据库地址 + user: 'root', // 数据库用户名 + password: '20041025', // 数据库密码 + database: 'class_k' ,// 使用的数据库 + waitForConnections: true, + connectionLimit: 10, + queueLimit: 0 +}); + +// 测试数据库连接 +pool.getConnection((err, connection) => { + if (err) { + console.error('Error connecting to the database:', err); + } else { + console.log('Database connected successfully!'); + connection.release(); // 释放连接 + } +}); + +module.exports = pool;