45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
|
|
/**
|
||
|
|
* 解锁所有表
|
||
|
|
*/
|
||
|
|
|
||
|
|
require('dotenv').config();
|
||
|
|
const mysql = require('mysql2/promise');
|
||
|
|
|
||
|
|
async function unlockAllTables() {
|
||
|
|
let connection;
|
||
|
|
|
||
|
|
try {
|
||
|
|
connection = await mysql.createConnection({
|
||
|
|
host: process.env.DB_HOST,
|
||
|
|
port: process.env.DB_PORT || 3306,
|
||
|
|
user: process.env.DB_USER,
|
||
|
|
password: process.env.DB_PASSWORD,
|
||
|
|
database: process.env.DB_DATABASE
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('✅ 已连接到数据库\n');
|
||
|
|
|
||
|
|
// 执行UNLOCK TABLES
|
||
|
|
console.log('🔓 正在解锁所有表...');
|
||
|
|
await connection.query('UNLOCK TABLES');
|
||
|
|
console.log('✅ 所有表已解锁\n');
|
||
|
|
|
||
|
|
// 提交任何待处理的事务
|
||
|
|
console.log('📝 提交待处理的事务...');
|
||
|
|
await connection.query('COMMIT');
|
||
|
|
console.log('✅ 事务已提交\n');
|
||
|
|
|
||
|
|
console.log('✅ 数据库解锁完成!\n');
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('❌ 操作失败:', error.message);
|
||
|
|
process.exit(1);
|
||
|
|
} finally {
|
||
|
|
if (connection) {
|
||
|
|
await connection.end();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
unlockAllTables();
|