君陌离的博客

vuePress-theme-reco 君陌离    2018 - 2020
君陌离的博客 君陌离的博客

Choose mode

  • dark
  • auto
  • light
首页
我的作品
  • 项目橱窗
  • blog模板
分类
  • 数据库
  • CSS
  • 摘记
  • JS
  • Node
  • Vue
  • React
  • GIT
  • Promise
  • Liunx
  • Xshell
  • ajax
  • WINDOWS
  • Python
  • 随笔
  • 脚手架
  • node
  • 自动化
标签
笔记
时间线
About Me
  • 关于我
  • 赞赏
Contact
  • GitHub
  • QQ
author-avatar

君陌离

70

文章

90

标签

首页
我的作品
  • 项目橱窗
  • blog模板
分类
  • 数据库
  • CSS
  • 摘记
  • JS
  • Node
  • Vue
  • React
  • GIT
  • Promise
  • Liunx
  • Xshell
  • ajax
  • WINDOWS
  • Python
  • 随笔
  • 脚手架
  • node
  • 自动化
标签
笔记
时间线
About Me
  • 关于我
  • 赞赏
Contact
  • GitHub
  • QQ
  • HTML5

  • JS

  • 微信小程序

  • 数据库

    • Node.js 连接 MongoDB
    • Node.js 连接 MySQL
  • React

  • Vue

  • vuepress

Node.js 连接 MySQL

vuePress-theme-reco 君陌离    2018 - 2020

Node.js 连接 MySQL

君陌离 2018-08-07 MySQL

# 安装依赖

cnpm install mysql
1

# 连接 MySQL

var mysql = require('mysql');
var connection = mysql.createConnection({
  host: '****************',
  user: 'user',
  password: 'password',
  database: 'blog'
});

connection.connect();
var sql = 'SELECT * FROM cmd';
connection.query(sql, function (error, results, fields) {
  if (error) throw error;
  console.log('--------------------------results----------------------------');
  console.log(results);
  console.log('--------------------------fields----------------------------');
  console.log(fields);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# 更多精彩内容

Node.js 连接 MySQL
mongo操作
liunx开启远程连接数据库

欢迎来到 您的站点名称($site.title)
看板娘