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
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.
In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.
The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.
SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.
Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.
MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.
MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.