37 lines
915 B
JavaScript
37 lines
915 B
JavaScript
const mysql = require('mysql2/promise');
|
|
|
|
async function updateAdminRole() {
|
|
const connection = await mysql.createConnection({
|
|
host: '8.130.78.179',
|
|
port: 9986,
|
|
user: 'sffx',
|
|
password: 'wF5WKm35Ddm5NDTn',
|
|
database: 'sffx'
|
|
});
|
|
|
|
try {
|
|
// 更新 admin 用户角色
|
|
const [result] = await connection.execute(
|
|
'UPDATE users SET role = ? WHERE username = ?',
|
|
['admin', 'admin']
|
|
);
|
|
|
|
console.log('✅ 更新成功!受影响的行数:', result.affectedRows);
|
|
|
|
// 查询验证
|
|
const [rows] = await connection.execute(
|
|
'SELECT id, username, email, realName, role, status FROM users WHERE username = ?',
|
|
['admin']
|
|
);
|
|
|
|
console.log('\n当前 admin 用户信息:');
|
|
console.table(rows);
|
|
} catch (error) {
|
|
console.error('❌ 更新失败:', error.message);
|
|
} finally {
|
|
await connection.end();
|
|
}
|
|
}
|
|
|
|
updateAdminRole();
|