Home>Article>Web Front-end> Let’s talk about how to operate MySQL in Node project
How to operate MySQL in Node project? The following article will talk to you about several SQL statements for managing databases, and introduce how to operate MySQL in Express projects. I hope it will be helpful to you!
Database is used toorganize,A warehouse that storesandmanagesdata. Today's world is an Internet world full of data, full ofa large amount of data. There are many sources of data, such as travel records, consumption records, web pages browsed, messages sent, etc. In addition to text type data, images, music, and sounds are all data. In order to facilitate the management of data in the Internet world, there is the concept ofdatabase management system(referred to as: database). Users can perform operations such as adding, querying, updating, and deleting data in the database.
Classification of database:
MySQL database(currently The most widely used and popular open source free database; Community Enterprise)
Oracle Database(Paid)
SQL Server database(charged)
Mongodb database(Community Enterprise)
Comparison: MySQL, Oracle, and SQL Server are traditional databases (also called: relational databases or SQL databases). These three have the same design concept and similar usage; while MongoDB is a new type of database (also called: non-relational databases or NoSQL databases). ), which makes up for the shortcomings of traditional databases to a certain extent.
Data organization structure of traditional database: In traditional database, the data organization structure is divided into database (database), data table (table) ), data row (row), and field (field).
The relationship between libraries, tables, rows, and fields in actual development: In actual project development, generally, each project corresponds to an independent database;Different data should be stored in different tables of the database, for example: user data is stored in the users table, and book data is stored in the books table;The specific information stored in each table is determined by the fields. For example: we can design the three fields of id, username, and password for the users table;table The rows in represent each specific piece of data.
For developers, they only need to install MySQL Server and Navicat to meet their development needs.
MySQL Server: Software specially used to provide data storage and services
Navicat: A visual MySQL management tool through which you can conveniently operate the data stored in MySQL Server
For specific installation tutorials, please refer to my previous article:MySQL Installation. With visualization tools, it becomes extremely easy for us to create tables and edit table data.
Structured Query Language, a programming language specificallyused to access and process databases. It allows us to manipulate the data in the database in the form of programming.
Note:
1) SQL is a database programming language 2) Written in SQL language The code that comes out is called a SQL statement 3) SQL language can only be used in relational databases (for example: MySQL, Oracle, SQL server). Non-relational databases (such as Mongodb) do not support SQL language.
SELECT statement
is used to query data from the table. The results of the execution are stored in a results table (called a result set). The syntax is as follows: (Note: Keywords in SQL statements are not case-sensitive, SELECT is equivalent to select, and FROM is equivalent to from).
-- 这是注释 -- 从 FROM 指定的【表中】,查询出【所有的】数据,* 表示【所有列】 SELECT * FROM 表名称 -- 从 FROM 指定的【表中】,查询出指定 列名称 (字段) 的数据 SELECT 列名称 FROM 表名称
INSERT INTO statement
is used to insert data Insert new data rows into the table.
-- 向指定表中插入数据,列的值通过 values 一一指定 -- 列和值要一一对应,多个列和多个值之间,要使用英文逗号分隔 insert into table_name (列1,列2...) values (值1,值2,值3)
Update statement
is used to modify the data in the table
-- 用 UPDATE 指定要更新哪个表中的数据,用 SET 指定列对应的新值,用 WHERE 指定更新的条件 update 表名称 set 列名称 = 新值 where 列名称 = 某值
DELETE statement
is used to delete rows in the table
-- 从指定的表中,根据 WHERE 条件,删除对应的数据行 delete from 表名称 where 列名称 = 值
is used to limit the selection criteria. In SELECT, UPDATE, and DELETE statements, the WHERE clause can be used to limit the selection criteria.
-- 查询语句中的 WHERE 条件 select 列名称 from 表名称 where 列 运算符 值 -- 更新语句中的 WHERE 条件 update 表名称 set 列=新值 where 列 运算符 值 -- 删除语句中的 WHERE 条件 delete from 表名称 where 列 运算符 值
The following operators can be used in the WHERE clause to limit the selection criteria:
Operator | Description |
---|---|
= | is equal to |
is not equal to | |
is greater than | |
Less than | |
Greater than or equal to | |
Less than Equal | |
Search for a certain pattern within a certain range | ##LIKE |
# 例如:可以通过 WHERE 子句来限定 SELECT 的查询条件: -- 查询 status 为 1 的所有用户 select * from users where status=1 -- 查询 id 大于 2 的所有用户 select * from users where id>2 -- 查询 username 不等于 admin 的所有用户 select * from users where username<>'admin' |
The above is the detailed content of Let’s talk about how to operate MySQL in Node project. For more information, please follow other related articles on the PHP Chinese website!