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 start
If 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!
Statement of this 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
Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.
I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.
Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.
Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.
MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.
The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA
MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.