Home >
Web Front-end >
JS Tutorial >
Let's talk about how node operates the MySQL database (add, delete, modify, check)
Let's talk about how node operates the MySQL database (add, delete, modify, check)
青灯夜游
Release: 2023-02-28 19:52:16
forward
2128 people have browsed it
How does node operate the MySQL database? The following article will take you through the methods of adding, deleting, modifying and querying the MySQL database in the node project. I hope it will be helpful to you!
Download and install mysql, check whether the installation is successful
net start mysql
Copy after login
Start mysql
You can right-click My Computer on the desktop and enter Computer Management to check whether mysql has been successfully run [Related tutorial recommendations: nodejs video tutorial]
Download and install navicat
Function: Provide us with the function of connecting and operating mysql database
Download
##www.navicat.com.cn/products#na…
Installation
Double-click, all the way to next
Use
to find the application, click to startIf the connection test passes, continue When you get down, you can click the OK button to officially connect to mysql. The effect after connecting is as follows:
Database Introduction
What is a database
English:
database The warehouse that saves and manages data is the database.
What is data? Files, pictures, videos, orders, usernames, passwords and more. These data need a special place to save and manage. Before we learned database technology, the data we used were all saved in the file system (db.json). We need a
specialized software to manage our data, which is a database.
insert into 表名(字段名1,字段名2,....) values (值1,值2,....)
Copy after login
注意:
字段的顺序要和值的顺序是完全匹配的
字段列表可以不与真实数据表中的字段完全相等,
可以省略一些不必要的字段
顺序与不需要与定义表时的顺序一致
如果是字符串类型的字段,其值要加"",如果是数值类型的字符串,其值不需要加“”
示例:
insert into stu (sex, weight, name) values ('男', 60, '庞凯')
Copy after login
sql-delete语句-删除数据
格式
delete from 表名 where 删除条件复制代码
Copy after login
注意:不指定条件将删除所有数据
示例
-- 删除id为14的同学
delete from stu where id=14
-- 删除的时候,不加条件,将删除stu表中的全部记录
delete from stu
Copy after login
sql-update语句-修改数据
格式
update 表名 set 字段1=值1, 字段2=值2,... where 修改条件
Copy after login
注意:
- 要修改的值使用键值对来表示
- 多个字段用,分隔
- 不指定条件,将修改当前表中全部的记录
Copy after login
示例
-- 修改id为1的同学的年龄为53
update stu set age=53 where id = 1
-- 修改id为1的同学的年龄为35,身高为160
update stu set age=35,height=160 where id = 1
-- 如果修改的时候,不加条件,则会修改全部的数据
update stu set weight = 60
Copy after login
sql-select-语句-数据查询
作用
把数据从数据库查出来
格式
SELECT 字段名1, 字段名2, ..... FROM 表名 WHERE <条件表达式>
Copy after login
示例
# 查询部分字段SELECT id,name,age FROM stu
# 查询所有字段SELECT * FROM stu
# 带条件的查询SELECT * FROM 表名 WHERE 条件1 and 条件2
Copy after login
where子句
select field1, field2... from 表名 查询表中的所有数据
where 可以使用条件来筛选查询出的结果
-- 查询所有的学生
select * from stu
-- 查询所有学生的id,name,height
select id,name,height from stu
-- 带条件的查询
select * from stu where 条件
-- 查询所有的男同学
select * from stu where sex='男'
-- 查询id为2的男同学
select * from stu where id=2
-- 查询年龄大于50的同学
select * from stu where age > 50
-- 查询年龄大于50岁的男同学
select * from stu where age>50 and sex='男'
-- 查询年龄在30~60之间的同学,包括30和60
select * from stu where age>=30 and age<=60
select * from stu where age between 30 and 60
The above is the detailed content of Let's talk about how node operates the MySQL database (add, delete, modify, check). For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn