当前位置:网站首页>Basic concept of database, installation and configuration of database, basic use of MySQL, operation of database in the project
Basic concept of database, installation and configuration of database, basic use of MySQL, operation of database in the project
2022-07-02 19:58:00 【Tianfubao 615】
( One ) Basic concepts of database
One 、 What is a database
Two 、 Common databases and classifications
3、 ... and 、 The data organization structure of traditional database
1、Excle The organization of data
2、 The data organization structure of traditional database
3、 Library in actual development 、 surface 、 That's ok 、 Field relationship
( Two ) Install and configure MySQL
One 、 Know what needs to be installed MySQL Related software
Two 、MySQL stay Mac Installation in environment
3、 ... and 、MySQL stay Windows Installation in environment
( 3、 ... and )MySQL Basic use of
One 、 Use MySQL Workbench Management database
1、 Connect database
2、 Understand the components of the main interface
3、 Create database
4、 Create data table
5、 Write data to the table
Two 、 Use SQL Management database
1、 What is? SQL
2、SQL What can be done
3、SQL Learning objectives of
3、 ... and 、SQL Of SELECT sentence
1、 grammar
2、SELECT* Example
3、SELECT Column name Example 
Four 、SQL Of INSERT INTO sentence
1、 grammar
2、INSERT INTO Example
5、 ... and 、SQL Of UPDATE sentence
1、 grammar
2、UPDATE An example of
6、 ... and 、SQL Of DELETE sentence
1、 grammar
2、DELETE An example of
7、 ... and 、SQL Of WHERE Clause
1、 grammar
2、 Can be found in WHERE Operators used in Clauses
3、WHERE Example of clause
8、 ... and 、SQL Of AND and OR Operator
1、 grammar
2、AND Operator example
3、OR Operator example 
Nine 、SQL Of ORDER BY Clause
1、 grammar 
2、 ORDER BY Clause —— Ascending sort
3、 ORDER BY Clause —— null
4、ORDER BY Clause —— Multiple sort
Ten 、SQL Of COUNT(*) function
1、 grammar
2、 COUNT(*) Example 
3、 Use AS Set an alias for the column 
( Four ) Operate in the project MySQL
One 、 Steps to operate a database in a project
Two 、 Installation and configuration mysql modular
1、 install mysql modular
2、 To configure mysql modular
// 1. Import database module
const mysql = require('mysql')
// 2. Establishment and MySQL The connection relationship of the database
const db = mysql.createPool({
host: '127.0.0.1' , // Database IP Address
user : 'root', // Login database account
password : 'admin123' , // Password to log in to the database
database: 'my_db_01' // Specify which database to operate on
})
3、 test mysql Whether the module can work properly
// test mysql Whether the module can work properly
db.query('select 1' , (err , results) => {
// mysql An error is reported during module operation
if(err) return console.log(err.message);
// Be able to successfully execute SQL sentence
console.log(results);
})
3、 ... and 、 Use mysql Module operation MySQL database
1、 Query data
// Inquire about users All the data in the table
const sqlStr = 'select * from users'
db.query(sqlStr , (err , results) => {
// Failed to query data
if(err) return console.log(err.message);
// Query data successful
// Be careful : If the execution is select Query statement , The result of execution is an array
console.log(results);
})
2、 insert data
// insert data
// 1. towards users In the table , Add a piece of data , among username The value of is Spider-Man,password The value of is pcc123
// To insert into users Data objects in the table
const user = {username :'Spider-Man' , password : 'pcc123'}
// 2. Define what to do SQL sentence
const sqlStr = 'insert into users (username , password) values (? , ?)'
// 3. perform SQL sentence
db.query(sqlStr , [user.username , user.password] , (err ,results) => {
// perform SQL Statement failure
if(err) return console.log(err.message);
// perform SQL Statement success
// Be careful : If the execution is insert into Insert statement , be results It's an object
// Sure adopt affectedRows attribute , To determine whether the data is successfully inserted
if(results.affectedRows === 1){
console.log(' Insert data succeeded !');
}
})
3、 Insert data Convenient way
// Demonstrate a convenient way to insert data
const user = {username :'Spider-Man' , password : 'pcc123'}
// 2. Define what to do SQL sentence
const sqlStr = 'insert into users set ?'
// 3. perform SQL sentence
db.query(sqlStr , [user.username , user.password] , (err ,results) => {
// perform SQL Statement failure
if(err) return console.log(err.message);
// perform SQL Statement success
// Be careful : If the execution is insert into Insert statement , be results It's an object
// Sure adopt affectedRows attribute , To determine whether the data is successfully inserted
if(results.affectedRows === 1){
console.log(' Insert data succeeded !');
}
})
4、 Update data
// Update data
const user = {id : 6 ,username :'aaa' , password : '111'}
// 2. Definition SQL sentence
const sqlStr = 'update users set username=? , password=? where id=?'
// perform SQL sentence
db.query(sqlStr, [user.username , user.password , user.id] , (err , results) => {
if(err) return console.log(err.message);
// Be careful : Yes update After statement , The result of execution is also an object , Can pass affectedRows Judge whether the update is successful
if(results.affectedRows === 1) console.log(' Update data successful !');
})
5、 A convenient way to update data
// Demonstrate a convenient way to update data
const user = {id : 6 ,username :'aaa' , password : '111'}
// 2. Definition SQL sentence
const sqlStr = 'update users set ? where id=?'
// perform SQL sentence
db.query(sqlStr, [user , user.id] , (err , results) => {
if(err) return console.log(err.message);
// Be careful : Yes update After statement , The result of execution is also an object , Can pass affectedRows Judge whether the update is successful
if(results.affectedRows === 1) console.log(' Update data successful !');
})
6、 Delete data
// Delete data
// Delete id= 5 Users of
const sqlStr = 'delete from users where id=?'
db.query(sqlStr, 5, (err , results) => {
if(err) return console.log(err.message);
// Be careful : Yes delete After statement , The result of execution is also an object , Can pass affectedRows Judge whether the deletion is successful
if(results.affectedRows === 1) console.log(' Delete data succeeded !');
})
7、 Mark deletion
// Mark deletion
const sqlStr = 'update users set status=? where id=?'
db.query(sqlStr , [1,6] , (err,results) => {
if(err) return console.log(err.message);
if(results.affectedRows === 1) {
console.log(' Tag deleted successfully ');
}
})
边栏推荐
- Dictionaries
- 励志!大凉山小伙全奖直博!论文致谢看哭网友
- R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线(indifference curve)
- Why do I have a passion for process?
- How to avoid duplicate data in gaobingfa?
- 字典
- 攻防世界pwn题:Recho
- AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
- Py's interpret: a detailed introduction to interpret, installation, and case application
- GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
猜你喜欢
CS5268完美代替AG9321MCQ Typec多合一扩展坞方案
Shardingsphere jdbc5.1.2 about select last_ INSERT_ ID () I found that there was still a routing problem
Introduction to mongodb chapter 03 basic concepts of mongodb
Overview of browser caching mechanism
Embedded (PLD) series, epf10k50rc240-3n programmable logic device
笔记本安装TIA博途V17后出现蓝屏的解决办法
KT148A语音芯片ic的软件参考代码C语言,一线串口
SQLite 3.39.0 release supports right external connection and all external connection
自動生成VGG圖像注釋文件
After eight years of test experience and interview with 28K company, hematemesis sorted out high-frequency interview questions and answers
随机推荐
VBScript详解(一)
CRM Customer Relationship Management System
CS5268完美代替AG9321MCQ Typec多合一扩展坞方案
CRM客户关系管理系统
Zabbix5 client installation and configuration
Esp32c3 crash analysis
Overview of browser caching mechanism
Kt148a voice chip IC user end self replacement voice method, upper computer
【NLP】一文详解生成式文本摘要经典论文Pointer-Generator
Taiwan SSS Xinchuang sss1700 replaces cmmedia cm6533 24bit 96KHz USB audio codec chip
JASMINER X4 1U深度拆解,揭开高效省电背后的秘密
编写完10万行代码,我发了篇长文吐槽Rust
Think about the huge changes caused by variables
台湾SSS鑫创SSS1700替代Cmedia CM6533 24bit 96KHZ USB音频编解码芯片
At compilation environment setup -win
burp 安装 license key not recognized
解决方案:VS2017 无法打开源文件 stdio.h main.h 等头文件[通俗易懂]
KS004 基于SSH通讯录系统设计与实现
JASMINER X4 1U deep disassembly reveals the secret behind high efficiency and power saving
【实习】解决请求参数过长问题