node. js + MySQL Database

Source: Internet
Author: User

Service, of course, can not be separated from the database, if you see the data on the cry, I suggest you still look at this article, do not do data cry ah haha

To do ' data cool ', hahaha

An installation

1. Wget-i-C http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

2. Yum-y Install mysql57-community-release-el7-10.noarch.rpm

3. Yum-y Install Mysql-community-server

Two-start

Systemctl Start Mysqld.service

Three Change the password

1. Find the initial password, grep "password"/var/log/mysqld.log

  

The first colon behind the initial password, of course, your machine will be different, but don't copy me

2. Mysql-uroot-p, after you enter the password, you enter the password you found on the login to MySQL

3. Change the password

3.1 Set global validate_password_policy=0;

3.2 Set global validate_password_length=1;

3.3 ALTER USER ' root ' @ ' localhost ' identified by ' your new password ';

IV Delete a temporary warehouse

Yum-y Remove Mysql57-community-release-el7-10.noarch

Five DEMO

 

var mysql = require (' mysql ');
var connection = Mysql.createconnection ({
Host: ' localhost ',
User: ' Root ',
Password: ' 11111111 ',
Database: ' Test '
});

Connection.connect ();

Connection.query (' Select + Solution ', function (Error, results, fields) {
if (error) throw error;
Console.log (' The solution is: ', results[0].solution);
});

var addsql = ' INSERT into websites (Id,name,url, alexa,country) VALUES (0,?,?,?,?) ';
var addsqlparams = [' Zcl ', ' https://zcl.com ', ' 11111111 ', ' CN '];
Connection.query (Addsql,addsqlparams,function (err,result) {
if (err) {
Console.log (' [INSERT ERROR]-', err.message);
Return
}
Console.log ('------------------------insert---------------------------');
Console.log (' INSERT ID: ', result);
Console.log ('---------------------------------------------------------');
});

var modsql = ' UPDATE websites SET name=?,url=? WHERE id=? ';
var modsqlparams =[' woodzcl ', ' http://zcl.com ', 6];
Connection.query (Modsql, modsqlparams,function (err, result) {
if (err) {
Console.log (' [UPDATE ERROR]-', err.message);
}
Console.log ('------------------------update---------------------------');
Console.log (' UPDATE affectedrows: ', result.affectedrows);
Console.log ('---------------------------------------------------------');

});

var delsql = ' DELETE from websites WHERE id=6 ';
Connection.query (Delsql,function (err, result) {
if (err) {
Console.log (' [DELETE ERROR]-', err.message);

Return
}
Console.log ('------------------------delete---------------------------');
Console.log (' DELETE affectedrows: ', result.affectedrows);
Console.log ('---------------------------------------------------------');
});

var sql = ' SELECT * from websites ';
Connection.query (SQL, function (err, result) {
if (err) {
Console.log (' [SELECT error]-', err.message);
}
Console.log ('------------------------select---------------------------');
Console.log (result);
Console.log ('---------------------------------------------------------');
});

Results

Node Test.js
The solution Is:2
------------------------Insert---------------------------
INSERT Id:okpacket {
fieldcount:0,
Affectedrows:1,
Insertid:9,
Serverstatus:2,
warningcount:0,
Message: ",
Protocol41:true,
changedrows:0}
---------------------------------------------------------
------------------------Update---------------------------
UPDATE affectedrows:0
---------------------------------------------------------
------------------------Delete---------------------------
DELETE affectedrows:0
---------------------------------------------------------
------------------------Select---------------------------
[Rowdatapacket {
Id:1,
Name: ' Google ',
URL: ' https://www.google.cm/',
Alexa:1,
Country: ' USA '},
Rowdatapacket {
Id:2,
Name: ' Weixin ',
URL: ' https://www.taobao.com/',
Alexa:13,
Country: ' CN '},
Rowdatapacket {
Id:3,
Name: ' Zcl ',
URL: ' http://www.runoob.com/',
alexa:4689,
Country: ' CN '},
Rowdatapacket {
Id:4,
Name:weibo ',
URL: ' http://weibo.com/',
ALEXA:20,
Country: ' CN '},
Rowdatapacket {
Id:5,
Name: ' Facebook ',
URL: ' https://www.facebook.com/',
Alexa:3,
Country: ' USA '},
Rowdatapacket {
Id:7,
Name: ' Zcl ',
URL: ' https://zcl.com ',
alexa:11111111,
Country: ' CN '},
Rowdatapacket {
Id:8,
Name: ' Zcl ',
URL: ' https://zcl.com ',
alexa:11111111,
Country: ' CN '},
Rowdatapacket {
Id:9,
Name: ' Zcl ',
URL: ' https://zcl.com ',
alexa:11111111,
Country: ' CN '}]
---------------------------------------------------------

Finally:

Okay, node. js I'm going to be here, if you have any questions, I'd like to discuss it with you.

Goodbye!

node. js + MySQL Database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.