SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| challenge |
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
CREATE DATABASE GAME_DB;
CREATE DATABASE USER_DB;
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
생성 완료
const testDbConnection = async (pool, dbName) => {
try {
const [rows] = await pool.query('SELECT 1 + 1 AS solution');
console.log(`${dbName} 테스트 쿼리 결과: ${rows[0].solution}`);
} catch (error) {
console.error(`${dbName} 테스트 쿼리 실행 중 오류 발생: ${error}`);
}
};
const testAllConnections = async (pools) => {
await testDbConnection(pools.GAME_DB, 'GAME_DB');
await testDbConnection(pools.USER_DB, 'USER_DB');
};
export { testDbConnection, testAllConnections };
정상적으로 연결되어 계산 결과가 로그로 나오는 모습