Generating commit message...
This commit is contained in:
72
simple-mysql-test.js
Normal file
72
simple-mysql-test.js
Normal file
@@ -0,0 +1,72 @@
|
||||
const mysql = require('mysql2');
|
||||
|
||||
// 测试环境配置
|
||||
const testConfig = {
|
||||
host: '192.168.0.240',
|
||||
port: 3306,
|
||||
user: 'root',
|
||||
password: 'aiot$Aiot123'
|
||||
};
|
||||
|
||||
// 生产环境配置
|
||||
const prodConfig = {
|
||||
host: '129.211.213.226',
|
||||
port: 9527,
|
||||
user: 'root',
|
||||
password: 'aiotAiot123!'
|
||||
};
|
||||
|
||||
function testConnection(config, environment) {
|
||||
return new Promise((resolve) => {
|
||||
console.log(`\n🔗 测试 ${environment} 连接...`);
|
||||
|
||||
const connection = mysql.createConnection(config);
|
||||
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error('❌ 连接失败:', err.message);
|
||||
connection.end();
|
||||
resolve({ success: false, error: err.message });
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ 连接成功');
|
||||
|
||||
// 测试简单查询
|
||||
connection.query('SELECT VERSION() as version', (err, results) => {
|
||||
if (err) {
|
||||
console.error('❌ 查询失败:', err.message);
|
||||
} else {
|
||||
console.log('📋 MySQL版本:', results[0].version);
|
||||
}
|
||||
|
||||
connection.end();
|
||||
resolve({ success: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('🚀 MySQL连接测试');
|
||||
console.log('='.repeat(40));
|
||||
|
||||
// 测试测试环境
|
||||
const testResult = await testConnection(testConfig, '测试环境');
|
||||
|
||||
console.log('\n' + '='.repeat(40));
|
||||
|
||||
// 测试生产环境
|
||||
const prodResult = await testConnection(prodConfig, '生产环境');
|
||||
|
||||
console.log('\n' + '='.repeat(40));
|
||||
console.log('📋 测试结果:');
|
||||
console.log('测试环境:', testResult.success ? '✅ 成功' : '❌ 失败');
|
||||
console.log('生产环境:', prodResult.success ? '✅ 成功' : '❌ 失败');
|
||||
|
||||
if (testResult.success && prodResult.success) {
|
||||
console.log('\n🎉 两个环境连接都成功!');
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in New Issue
Block a user