refactor(backend): 重构动物相关 API 接口
- 更新了动物数据结构和相关类型定义 - 优化了动物列表、详情、创建、更新和删除接口 - 新增了更新动物状态接口 - 移除了与认领记录相关的接口 -调整了 API 响应结构
This commit is contained in:
60
test_db_connection.js
Normal file
60
test_db_connection.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
// 数据库配置
|
||||
const dbConfig = {
|
||||
host: '129.211.213.226',
|
||||
port: 9527,
|
||||
user: 'root',
|
||||
password: 'aiotAiot123!',
|
||||
database: 'jiebandata',
|
||||
connectionLimit: 10,
|
||||
charset: 'utf8mb4',
|
||||
timezone: '+08:00',
|
||||
waitForConnections: true,
|
||||
queueLimit: 0,
|
||||
// 添加连接超时配置
|
||||
connectTimeout: 10000, // 10秒连接超时
|
||||
acquireTimeout: 10000, // 10秒获取连接超时
|
||||
timeout: 10000 // 10秒查询超时
|
||||
};
|
||||
|
||||
async function testConnection() {
|
||||
let connection;
|
||||
try {
|
||||
console.log('尝试连接数据库...');
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
console.log('✅ 数据库连接成功');
|
||||
|
||||
// 测试查询
|
||||
const [rows] = await connection.execute('SELECT 1 as test');
|
||||
console.log('✅ 数据库查询测试成功:', rows);
|
||||
|
||||
// 查询管理员表
|
||||
const [admins] = await connection.execute('SELECT id, username, role FROM admins LIMIT 3');
|
||||
console.log('✅ 管理员表查询成功:');
|
||||
console.table(admins);
|
||||
|
||||
await connection.end();
|
||||
console.log('✅ 数据库连接已关闭');
|
||||
} catch (error) {
|
||||
console.error('❌ 数据库连接失败:', error.message);
|
||||
if (error.code) {
|
||||
console.error('错误代码:', error.code);
|
||||
}
|
||||
if (error.errno) {
|
||||
console.error('错误编号:', error.errno);
|
||||
}
|
||||
if (error.syscall) {
|
||||
console.error('系统调用:', error.syscall);
|
||||
}
|
||||
if (connection) {
|
||||
try {
|
||||
await connection.end();
|
||||
} catch (closeError) {
|
||||
console.error('关闭连接时出错:', closeError.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testConnection();
|
||||
Reference in New Issue
Block a user