init
This commit is contained in:
52
scripts/simple-db-check.js
Normal file
52
scripts/simple-db-check.js
Normal file
@@ -0,0 +1,52 @@
|
||||
// 簡單的資料庫檢查
|
||||
require('dotenv').config({ path: '.env.local' })
|
||||
const mysql = require('mysql2/promise')
|
||||
|
||||
async function simpleCheck() {
|
||||
const config = {
|
||||
host: process.env.DB_HOST,
|
||||
port: parseInt(process.env.DB_PORT),
|
||||
database: process.env.DB_DATABASE,
|
||||
user: process.env.DB_USERNAME,
|
||||
password: process.env.DB_PASSWORD,
|
||||
}
|
||||
|
||||
try {
|
||||
const connection = await mysql.createConnection(config)
|
||||
console.log('🔗 連接到 MySQL 資料庫...')
|
||||
|
||||
// 直接查詢表
|
||||
console.log('\n📋 檢查資料庫表...')
|
||||
const [tables] = await connection.execute('SHOW TABLES')
|
||||
|
||||
console.log(`\n📊 找到 ${tables.length} 個表:`)
|
||||
tables.forEach((table, index) => {
|
||||
const tableName = Object.values(table)[0]
|
||||
console.log(` ${index + 1}. ${tableName}`)
|
||||
})
|
||||
|
||||
// 檢查每個表的結構
|
||||
for (const table of tables) {
|
||||
const tableName = Object.values(table)[0]
|
||||
console.log(`\n🔍 表結構: ${tableName}`)
|
||||
|
||||
try {
|
||||
const [columns] = await connection.execute(`DESCRIBE ${tableName}`)
|
||||
console.log(' 欄位:')
|
||||
columns.forEach(col => {
|
||||
console.log(` - ${col.Field}: ${col.Type} ${col.Null === 'YES' ? 'NULL' : 'NOT NULL'} ${col.Key || ''}`)
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(` ❌ 無法讀取表結構: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
await connection.end()
|
||||
console.log('\n✅ 資料庫檢查完成')
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 資料庫檢查失敗:', error)
|
||||
}
|
||||
}
|
||||
|
||||
simpleCheck()
|
Reference in New Issue
Block a user