zoukankan      html  css  js  c++  java
  • Node.js连接mysql

    ================创建链接池=====================
    var mysql = require('mysql');
    var pool = mysql.createPool({
    connectionLimit : 10,
    host : 'example.org',
    user : 'bob',
    password : 'secret',
    database : 'my_db'
    });

    pool.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
    if (error) throw error;
    console.log('The solution is: ', rows[0].solution);
    });

    pool.end(function (err) {
    // all connections in the pool have ended
    });


    =================创建单个链接======================
    var mysql = require('mysql');
    var connection = mysql.createConnection({
    host : 'localhost',
    user : 'me',
    password : 'secret',
    database : 'my_db'
    });

    connection.connect(); //这行代码不写,也可以通过调用查询来隐式地建立连接:

    connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
    if (error) throw error;
    console.log('The solution is: ', results[0].solution);
    });

    connection.end();

  • 相关阅读:
    SpringBoot 整合Shiro
    Shiro 学习
    SpringBoot 整合security、thymeleaf
    【SpringBoot__Mybatis】整合MyBatis 配置文件版2
    SpringBoot 配置Druid数据源及监控
    lombok 使用
    thymeleaf 常用
    随机模块
    md5加密
    python正则
  • 原文地址:https://www.cnblogs.com/xbblogs/p/6973631.html
Copyright © 2011-2022 走看看