Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mysql connection in node js

/*
To download and install the "mysql" module, 
open the Command Terminal and execute the following: npm install mysql  
*/
var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: "12345"  
});  
con.connect(function(err) {  
  if (err) throw err;  
  console.log("Connected!");  
});  
Comment

connect mysql to node js

var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: "12345"  
});  
con.connect(function(err) {  
  if (err) throw err;  
  console.log("Connected!");  
});  
Comment

nodejs Mysql connection

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'example.org',
  user     : 'bob',
  password : 'secret'
});
 
connection.connect(function(err) {
  if (err) {
    console.error('error connecting: ' + err.stack);
    return;
  }
 
  console.log('connected as id ' + connection.threadId);
});
Comment

nodejs mysql connection

let connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'todoapp'
});
Code language: JavaScript (javascript)
Comment

nodejs mysql connection

connection.connect(function(err) {
  if (err) {
    return console.error('error: ' + err.message);
  }

  console.log('Connected to the MySQL server.');
});
Code language: JavaScript (javascript)
Comment

nodejs mysql

// you can't connect to mysql in client side js

// but you can use it in nodejs which is server-side
// for nodejs you can use package named mysql2
npm i mysql2

// read Doc here 
// https://www.npmjs.com/package/mysql2
Comment

PREVIOUS NEXT
Code Example
Javascript :: where to place async in const function 
Javascript :: js find space in string 
Javascript :: javascript store text file into string 
Javascript :: react navigation navigator types 
Javascript :: dropzone on success all files 
Javascript :: jquery insertafter 
Javascript :: How to calc() height in react native for styling 
Javascript :: bootstrap prevent dropdown from closing on click 
Javascript :: how to create jquery function 
Javascript :: tabuada js 
Javascript :: how to get the max value of two variables in math 
Javascript :: javascript click events 
Javascript :: string to html 
Javascript :: nuxt-link name params 
Javascript :: how to upload file in material ui 
Javascript :: svelte ondestroy 
Javascript :: json javascript 
Javascript :: settext javascript 
Javascript :: how to make hide/show btn in js 
Javascript :: textField input font color React Material UI 
Javascript :: website edit js 
Javascript :: cypress custom error message 
Javascript :: jest mock react-redux hooks 
Javascript :: javascript get elements that exist in two arrays 
Javascript :: javascript backslash 
Javascript :: Unable to locate package node 
Javascript :: react fetch url 
Javascript :: how to change the choose file button text in react 
Javascript :: vue js reload page 
Javascript :: load base64 image in tab javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =