node.js 连接本地mysql8.0版本出现的问题 window系统
1.cmd管理员进入mysql文件夹的bin目录
2.键入命令行 mysql -u -root -p
3.输入密码
4. alter USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRENEVER; (必填)
5.alter USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';(修改自己的密码)
6.FLUSH PRIVILEGES;(刷新权限)
7.完成
8.npm install mysql
9.编写一套简单的查询 mysql.js
var mysql = require('mysql'); var connection = mysql.createConnection({ host: "127.0.0.1", user: "root", password: "123456", port: '3306', database: 'test' }); connection.connect(); connection.query('select * from user',function(error, results, fields){ if(error) throw error; console.log("这是结果:"+JSON.stringify(results)) }); connection.end();