MySQL
MySQL is an open-source relational database management system.
Official Websitehttps://mysql.com
TagsSQLDatabase
- JavaScript
- Python
Documentationhttps://sidorares.github.io/node-mysql2/docs
NodeJS packagehttps://www.npmjs.com/package/mysql2
Version3.9.1
Source Codehttps://github.com/sidorares/node-mysql2
Documentationhttps://dev.mysql.com/doc/connector-python/en/
Pypi packagehttps://pypi.org/project/mysql-connector-python/
Version8.3.0
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 parameters you can see here.
Here is 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.
- JavaScript
- Python
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;
}
});
Integration
New integration from credential
mysql_connection = yepcode.integration.mysql('credential-slug')
New integration from plain authentication data
import mysql.connector
mysql_connection = mysql.connector.connect(
host="localhost",
port=3306,
user="user",
password="password",
database="database"",
)
SELECT Text Only
SELECT Text only
cursor = mysql_connection.cursor(dictionary=True)
query = "SELECT * FROM your_table where id = 1"
cursor.execute(query)
SELECT Parametrized
SELECT Parameterized
cursor = mysql_connection.cursor(dictionary=True)
query = "SELECT * FROM your_table WHERE id = %s"
cursor.execute(query, [2])
SELECT Query Object
SELECT Query object
cursor = mysql_connection.cursor(dictionary=True)
query = "SELECT * FROM your_table WHERE id = %(id)s"
cursor.execute(query, {"id": 2})
INSERT Text Only
INSERT Text only
cursor = mysql_connection.cursor()
query = "INSERT INTO your_table (id, name, price) VALUES (2, 'bar', 19.99)"
cursor.execute(query)
mysql_connection.commit()
INSERT Parameterized
INSERT Parameterized
cursor = mysql_connection.cursor()
query = "INSERT INTO your_table (id, name, price) VALUES (%s, %s, %s)"
cursor.execute(query, [3, "baz", 29.99])
mysql_connection.commit()
INSERT Query Object
INSERT Query object
cursor = mysql_connection.cursor()
query = "INSERT INTO your_table (id, name, price) VALUES (%(id)s, %(name)s, %(price)s)"
cursor.execute(query, {"id": 4, "name": "qux", "price": 39.99})
mysql_connection.commit()