MySQL
MySQL is an open-source relational database management system.

Official Websitehttps://mysql.com
NodeJS packagehttps://www.npmjs.com/package/mysql2
Version2.3.3
Source Codehttps://github.com/sidorares/node-mysql2
TagsSQL, Database
Network Connection needs
This integration needs network access to the server where the service is running.
See the Network access page for details about how to achieve that.
Credential configuration
To configure this credential you need the host
, port
, username
, password
and database
to connect to mysql.
Optionally you can set any of the extra config params you can see here.
Here you have an example of a filled credential configuration form in YepCode:

MySQL snippets available in editor
note
The title is the triggering text for YepCode to autocomplete the script
Integration
New integration from credential
const mysqlClient = yepcode.integration.mysql('credential-slug')
New integration from plain authentication data
const mysql = require('mysql2');
const mysqlClient = mysql.createConnection({
user: 'mysql',
password: '1234abcd',
host: 'localhost',
database: 'testdb',
port: 3306,
connectTimeout: 2000
});
Connect
Connect (callback)
mysqlClient.connect((err) => {
if(err){
throw err
}
// Your query here
})
Disconnect
Disconnect (callback)
mysqlClient.end(function(err) {
if(err){
throw err
}
console.log('Connection closed!')
});
SELECT Text only
SELECT Text only with callback
mysqlClient.query('SELECT id, name, price FROM products', function (error, rows, fields) {
if(error){
console.error(error.stack)
throw error
}
console.log(rows.forEach((row) => console.log(row.name)));
});
SELECT Parametrized
SELECT Parameterized (callback)
mysqlClient.query(
`SELECT id, name, price
FROM products
WHERE price > ? AND stock > ?`,
[100, 200],
function (error, rows, fields) {
if (error) {
console.error(error.stack);
throw error;
}
console.log(rows.forEach((row) => console.log(row.name)));
}
);
SELECT Query object
SELECT Query object (callback)
const query = {
sql: `SELECT id, name, price
FROM products
WHERE price > ? AND stock > ?`,
timeout: 40000,
values: [100, 200],
};
mysqlClient.query(query, function (error, rows, fields) {
if (error) {
console.error(error.stack);
throw error;
}
console.log(rows.forEach((row) => console.log(row.name)));
});
INSERT Text only
INSERT (callback)
mysqlClient.query(
"INSERT INTO products(id, name, price, stock) VALUES('12345', 'FOO', 12, 50)",
function (error, results, fields) {
if (error) {
console.error(error.stack);
throw error;
}
});
INSERT Parameterized
INSERT (callback)
mysqlClient.query(
'INSERT INTO products(id, name, price, stock) VALUES(?, ?, ?, ?)',
['12345', 'FOO', 12, 50],
function (error, results, fields) {
if (error) {
console.error(error.stack);
throw error;
}
});
INSERT Query object (callback)
const query = {
sql: 'INSERT INTO products(id, name, price, stock) VALUES(?, ?, ?, ?)',
timeout: 40000,
values: ['12345', 'FOO', 12, 50]
};
mysqlClient.query(query, function (error, results, fields) {
if (error) {
console.error(error.stack);
throw error;
}
});