How to use the createConnection function from mysql2

Find comprehensive JavaScript mysql2.createConnection code examples handpicked from public code repositorys.

435
436
437
438
439
440
441
442
443
444
    queryablePromise.end()
    queryablePromise = undefined
  }
}

queryable = mysql.createConnection(connectionOptions)
queryable.connect()

mysqlPromise.createConnection(connectionOptions).then(connection => {
  queryablePromise = connection
fork icon211
star icon536
watch icon296

+ 3 other calls in file

315
316
317
318
319
320
321
322
323
324
325
*/
}


//setting up mySQL database, still needs work
//from lec8 REST server example slides
const dbCon = mysql.createConnection(
    {
        host:"localhost",
        user: "root",
        password: "passwd" //change this to the password for your mysql root account
fork icon1
star icon3
watch icon4

+ 3 other calls in file

0
1
2
3
4
5
6
7
8
9
10
const { Sequelize } = require('sequelize');
const mysql = require('mysql2');


module.exports.createDb = async function createDb() {
    // Create connection to MySQL
    const connection = mysql.createConnection({
        host: 'localhost',
        user: 'root',
        password: ''
    });
fork icon0
star icon2
watch icon2

32
33
34
35
36
37
38
39
40
41
42
43
    tableNames.trades = process.env.DATABASE_TRADE_TABLE_NAME;
} if (typeof process.env.DATABASE_COSMETIC_TABLE_NAME != "undefined"){
    tableNames.cosmetics = process.env.DATABASE_COSMETIC_TABLE_NAME;
}


const connection = mysql2.createConnection(databaseLogin);


// Having a variable which checks whether the connection is successful
// instead of throwing an error when trying to connect allows the app
// to continue running even if the connection was unsuccessful. Other
fork icon0
star icon2
watch icon1

+ 14 other calls in file

-1
fork icon0
star icon1
watch icon1

+ 3 other calls in file

7
8
9
10
11
12
13
14
15
16
17
18
const app = express();
app.use(cors()); // CORS(교차 출처 리소스 공유)를 사용 설정하여 다른 도메인의 요청을 허용합니다.
app.use(bodyParser.json());// 수신 요청에 대해 JSON 본문 구문 분석 활성화




const connection = mysql.createConnection({ // 제공된 연결 정보로 MySQL 연결을 설정합니다.
    host: 'mj-fp-db.c2ghfqx8jn0l.ap-northeast-2.rds.amazonaws.com', // AWS RDS endpoint
    user: 'mjade0116', // AWS RDS username
    password: 'rainstorm116', // AWS RDS password
    database: 'MJ_FP', // MySQL database name
fork icon0
star icon1
watch icon0

2
3
4
5
6
7
8
9
10
11
12
13
const { query } = require('express');
const app = express();
const PORT = 8080;




let conn = mysql.createConnection({
  host: 'localhost',
  user: 'gfa',
  database: 'bookstore',
});
fork icon0
star icon1
watch icon1

+ 3 other calls in file

3
4
5
6
7
8
9
10
11
12
13
14
15




const express = require("express");
const sql = require("mysql2");


const connection = sql.createConnection({
    host: 'localhost', //database running on a localhost
    user: 'gfa',
    database: 'reddit',
  }
fork icon0
star icon1
watch icon1

+ 3 other calls in file

3
4
5
6
7
8
9
10
11
12
const { mysql } = require('../Connect/conect');
const { id } = require('../module/modulars');
const { TablesController } = require('../controller/tables-controller');
const e = require('express');
const moment = require('moment');
const connection = mysqla.createConnection({
    host: 'localhost',
    user: 'nhan',
    password: 'root',
    database: 'dipe'
fork icon0
star icon0
watch icon1

+ 4 other calls in file

8
9
10
11
12
13
14
15
16
17
18
const mysql = require('mysql2');
const { check } = require("express-validator");
app.use(cors());
app.use(bodyparser.json());


const db = mysql.createConnection({
	host: 'localhost',
	user: 'root',
	password: '',
	database:'labreservationsystem',
fork icon0
star icon0
watch icon1

+ 4 other calls in file

15
16
17
18
19
20
21
22
23
24
25
26
app.use(body.urlencoded({ extended: false }))
let bcrypt = require('bcryptjs');


app.use(express.static('assets'))


var con = mysql.createConnection({
    host: "localhost",
    user: 'root',
    password: 'root',
    database: 'job_application_db'
fork icon0
star icon0
watch icon1

+ 14 other calls in file

-1
fork icon0
star icon0
watch icon1

+ 9 other calls in file

7
8
9
10
11
12
13
14
15
16
17
18


const app = express();
app.use(cors());
app.use(express.json());


const con = mysql.createConnection({
    host: 'localhost',
    port: "3306",
    user: "root",
    password: "0000",  
fork icon0
star icon0
watch icon1

+ 9 other calls in file

20
21
22
23
24
25
26
27
28
29
30
31
// ให้อนุญาตหรือไม่อนุญาต ร้องขอทรัพยากรใดๆ ในหน้า Web ที่ถูกเรียกจาก Domain อื่น
// ที่ไม่ใช่ Domain ที่หน้า Web นั้นอยู่
app.use(express.json());
app.use(cors());


const db = mysql2.createConnection(process.env.DATABASE_URL);


app.get("/", (req, res) => {
    res.json("This is server-side. AKA Backend")
})
fork icon0
star icon0
watch icon1

+ 9 other calls in file

-2
fork icon0
star icon0
watch icon1

+ 3 other calls in file

25
26
27
28
29
30
31
32
33
34
35
36
37
38


//DATABASE modules and other declarations


require('dotenv').config();
const mysql = require('mysql2');
const connection = mysql.createConnection(process.env.DATABASE_URL); //gets the url of the database, allowing the connection to be made


connection.connect() //initialises connection to the PlanetScale API.


//Stuff for decoding JSON
fork icon0
star icon0
watch icon0

16
17
18
19
20
21
22
23
24
25
26
27
// ให้อนุญาตหรือไม่อนุญาต ร้องขอทรัพยากรใดๆ ในหน้า Web ที่ถูกเรียกจาก Domain อื่น
// ที่ไม่ใช่ Domain ที่หน้า Web นั้นอยู่
app.use(express.json());
app.use(cors());


const db = mysql2.createConnection(process.env.DATABASE_URL)


app.get("/", (req, res) => {
    res.json("This is server-side. AKA Backend")
})
fork icon0
star icon0
watch icon1

+ 4 other calls in file

3
4
5
6
7
8
9
10
11
12
const { mysql } = require('../Connect/conect');
const { id } = require('../module/modulars');
const { TablesController } = require('../controller/tables-controller');
const e = require('express');
const moment = require('moment');
var connection = mysqla.createConnection({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME
fork icon0
star icon0
watch icon1

+ 4 other calls in file

-1
fork icon0
star icon0
watch icon1

+ 4 other calls in file