You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
882 B
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const mysql = require('mysql2');
const connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'Skyinno251,',
database : 'appserver'
});
connection.connect((err) => {
if (err) {
console.error('连接失败: ' + err.stack);
return;
}
console.log('连接成功线程ID: ' + connection.threadId);
//
var sql = 'SELECT * FROM temperature where id < 50';
//查
connection.query(sql,function (err, result) {
if(err){
console.log('[SELECT ERROR] - ',err.message);
connection.end();
return;
}
console.log('--------------------------SELECT----------------------------');
console.log(result);
console.log('------------------------------------------------------------\n\n');
connection.end();
});
});