[英]Cant connect Node.js to MariaDB
Ok so I tried to connect node.js with my server mariaDB with this code好的,所以我尝试使用此代码将 node.js 与我的服务器 mariaDB 连接
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: 'mydb.com',
user:'myUser',
password: 'myPassword',
connectionLimit: 5
});
async function asyncFunction() {
let conn;
try {
conn = await pool.getConnection();
const rows = await conn.query("SELECT 1 as val");
console.log(rows); //[ {val: 1}, meta: ... ]
const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }
} catch (err) {
throw err;
} finally {
if (conn) return conn.end();
}
}
Unfortunately.It's doesn't work.The strange thing is I didnt recieve any eror messages.I wanna know In which I did wrong and how to fix it.不幸的是,它不起作用。奇怪的是我没有收到任何错误消息。我想知道我做错了什么以及如何解决它。
There!那里! Here is what I use
这是我使用的
const pool = mysql.createPool({
connectionLimit : 100,
host : 'localhost',
user : 'rashid',
password : config.get('turing-password'),
database : config.get('turing-db-name'),
multipleStatements:true
})
module.exports.connect = pool.getConnection(function(err, connection) {
if(err)
logger.info('we could not connect to the database');
logger.info('We successfully connected to the database');
})
Please make sure if your running on localhost use the host as localhost请确保您在 localhost 上运行时使用主机作为 localhost
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.