当前位置:网站首页>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 ');
}
})
边栏推荐
- Yes, that's it!
- Istio1.12: installation and quick start
- Workplace four quadrant rule: time management four quadrant and workplace communication four quadrant "suggestions collection"
- upload-labs
- burp 安装 license key not recognized
- Infix expression is converted to suffix expression (C language code + detailed explanation)
- PXE installation "recommended collection"
- Génération automatique de fichiers d'annotation d'images vgg
- 使用IDM下载百度网盘的文件(亲测有用)[通俗易懂]
- Detailed tutorial on installing stand-alone redis
猜你喜欢

B-end e-commerce - reverse order process

After writing 100000 lines of code, I sent a long article roast rust

攻防世界pwn题:Recho

Why do I have a passion for process?

Refactoring: improving the design of existing code (Part 2)

Attack and defense world PWN question: Echo

笔记本安装TIA博途V17后出现蓝屏的解决办法

Taiwan SSS Xinchuang sss1700 replaces cmmedia cm6533 24bit 96KHz USB audio codec chip

CS5268完美代替AG9321MCQ Typec多合一扩展坞方案

Complete example of pytorch model saving +does pytorch model saving only save trainable parameters? Yes (+ solution)
随机推荐
Postman interface test practice, these five questions you must know
Automatic reading of simple books
450 Shenxin Mianjing 1
分享几个图床网址,便于大家分享图片
Kt148a voice chip IC user end self replacement voice method, upper computer
After 65 days of closure and control of the epidemic, my home office experience sharing | community essay solicitation
B-end e-commerce - reverse order process
有时候只查询一行语句,执行也慢
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
AcWing 1126. Minimum cost solution (shortest path Dijkstra)
自动化制作视频
Esp32c3 crash analysis
Génération automatique de fichiers d'annotation d'images vgg
R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线(indifference curve)
In depth understanding of modern web browsers (I)
Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
Embedded (PLD) series, epf10k50rc240-3n programmable logic device
How to set priorities in C language? Elaborate on C language priorities
AcWing 341. Optimal trade solution (shortest path, DP)
励志!大凉山小伙全奖直博!论文致谢看哭网友

