parent
77f39dc63d
commit
a1365dd77f
@ -1,24 +1,24 @@
|
|||||||
const mysql = require('mysql2/promise');
|
const mysql = require('mysql2/promise');
|
||||||
|
|
||||||
// 创建连接池
|
// 创建连接池
|
||||||
const pool = mysql.createPool({
|
const pool = mysql.createPool({
|
||||||
host: 'localhost', // 数据库地址
|
host: 'localhost', // 数据库地址
|
||||||
user: 'root', // 数据库用户名
|
user: 'root', // 数据库用户名
|
||||||
password: '20041025', // 数据库密码
|
password: '123456', // 数据库密码
|
||||||
database: 'class_k' ,// 使用的数据库
|
database: 'class_k' ,// 使用的数据库
|
||||||
waitForConnections: true,
|
waitForConnections: true,
|
||||||
connectionLimit: 10,
|
connectionLimit: 10,
|
||||||
queueLimit: 0
|
queueLimit: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
// 测试数据库连接
|
// 测试数据库连接
|
||||||
pool.getConnection((err, connection) => {
|
pool.getConnection((err, connection) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error connecting to the database:', err);
|
console.error('Error connecting to the database:', err);
|
||||||
} else {
|
} else {
|
||||||
console.log('Database connected successfully!');
|
console.log('Database connected successfully!');
|
||||||
connection.release(); // 释放连接
|
connection.release(); // 释放连接
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = pool;
|
module.exports = pool;
|
||||||
|
Loading…
Reference in new issue