62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
|
|
const mysql = require('mysql2/promise');
|
|||
|
|
|
|||
|
|
async function testDevConnection() {
|
|||
|
|
console.log('🧪 测试开发环境数据库连接...');
|
|||
|
|
|
|||
|
|
const dbConfig = {
|
|||
|
|
host: '192.168.0.240',
|
|||
|
|
port: 3306,
|
|||
|
|
user: 'root',
|
|||
|
|
password: 'aiotAiot123!',
|
|||
|
|
database: 'jiebandata',
|
|||
|
|
connectTimeout: 10000
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
console.log('🔗 尝试连接到开发服务器:', dbConfig.host + ':' + dbConfig.port);
|
|||
|
|
|
|||
|
|
const connection = await mysql.createConnection(dbConfig);
|
|||
|
|
console.log('✅ 开发环境连接成功!');
|
|||
|
|
|
|||
|
|
// 测试基本查询
|
|||
|
|
const [rows] = await connection.execute('SELECT 1 as test');
|
|||
|
|
console.log('✅ 基本查询测试通过');
|
|||
|
|
|
|||
|
|
// 检查表结构
|
|||
|
|
const [tables] = await connection.execute(`
|
|||
|
|
SELECT TABLE_NAME
|
|||
|
|
FROM INFORMATION_SCHEMA.TABLES
|
|||
|
|
WHERE TABLE_SCHEMA = 'jiebandata'
|
|||
|
|
`);
|
|||
|
|
|
|||
|
|
console.log('📊 数据库中的表:', tables.map(t => t.TABLE_NAME).join(', ') || '暂无表');
|
|||
|
|
|
|||
|
|
await connection.end();
|
|||
|
|
console.log('🎉 开发环境测试完成');
|
|||
|
|
return true;
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ 开发环境连接失败:', error.message);
|
|||
|
|
console.log('🔍 错误代码:', error.code);
|
|||
|
|
|
|||
|
|
if (error.code === 'ECONNREFUSED') {
|
|||
|
|
console.log('💡 可能原因: 开发服务器未启动或网络不可达');
|
|||
|
|
} else if (error.code === 'ER_ACCESS_DENIED_ERROR') {
|
|||
|
|
console.log('💡 可能原因: 用户名或密码错误');
|
|||
|
|
} else if (error.code === 'ER_BAD_DB_ERROR') {
|
|||
|
|
console.log('💡 可能原因: 数据库不存在');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 执行测试
|
|||
|
|
testDevConnection().then(success => {
|
|||
|
|
if (success) {
|
|||
|
|
console.log('\n✅ 所有测试通过!开发环境配置正确');
|
|||
|
|
} else {
|
|||
|
|
console.log('\n⚠️ 开发环境配置需要检查');
|
|||
|
|
}
|
|||
|
|
process.exit(success ? 0 : 1);
|
|||
|
|
});
|