varMySQL = require ('MySQL');varconn =mysql.createconnection ({host:'localhost', User:'Root', Password:"', Database:'Nodejs', Port:3306}); Conn.connect ();//Enquiry//conn.query (' SELECT * ' from user where name= ' Wangzhiwei ', function (err, result) {//if (err) throw err;//Console.log (result);// })//New//conn.query (' INSERT INTO user ' (Username,password) VALUES ("Huxiaona", "123456") ', function (err, result) {//if (err) throw err;//Console.log (result);// })//Delete//conn.query (' Delete from user where username= ' Wupeigui ', function (err, result) {//if (err) throw err;//Console.log (result);// })Conn.query ('Update user Set id= "1" where username= "Huxiaona"', Function (err,result) {if(ERR) {Throwerr}; Console.log ("Modify Data Success");}) Conn.end ();
One point to point out is that when NPM install MySQL, in the program, even if you load MySQL into the Nodejs node_modules folder is not crest matter, may be I operate the wrong bar, have to know the next Ah, thank you, The front end has the data feeling immediately hanging hanging, a will build a website management system to play, simple and clear, but nodejs how to use the session, I Baidu a bit is said to use a cookie to replace, so not very good
Nodejs link MySQL database, perform simple additions and deletions to check the operation