forked from benborla/mcp-server-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-db.js
More file actions
43 lines (34 loc) · 1.13 KB
/
Copy pathtest-db.js
File metadata and controls
43 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import mysql from 'mysql2/promise';
async function testConnection() {
try {
console.log('Attempting to connect to MySQL...');
// Connection configuration
const config = {
host: process.env.MYSQL_HOST || '127.0.0.1',
port: process.env.MYSQL_PORT || 3306,
user: process.env.MYSQL_USER || 'root',
password: process.env.MYSQL_PASSWORD || '',
database: process.env.MYSQL_DATABASE
};
console.log('Connection config:', {
...config,
password: config.password ? '******' : 'not set'
});
// Create connection pool
const pool = mysql.createPool(config);
// Test connection
const connection = await pool.getConnection();
console.log('Connection successful!');
// Get server info
const [rows] = await connection.query('SELECT VERSION() as version');
console.log('MySQL Version:', rows[0].version);
// Release connection
connection.release();
// Close pool
await pool.end();
console.log('Connection pool closed');
} catch (error) {
console.error('Error connecting to MySQL:', error);
}
}
testConnection();