介绍

mysql npm包 是一个nodejs的模块,由JavaScript编写

安装

npm install mysql

建立连接

var mysql = require('mysql');//引用Mysql
var connection = mysql.createConnection({//配置连接
    host: 'localhost',//数据库地址
    user : "user",//数据库用户
    password: "password",..//数据库密码
    database : "database"//需要连接的数据库
});

connection.connect();//连接数据库

connection.query('select ! + 1 AS solution',function(err,rows,fields){//执行sql语句
    if(err) throw err ;
    console.log('thesolution is:' rows[0].solution);
});

connection.end();//断开连接


相关文章:

  • 2022-12-23
  • 2021-06-13
  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-05-04
  • 2021-05-28
猜你喜欢
  • 2022-12-23
  • 2021-12-10
  • 2021-11-10
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案