Database concepts and basic MySQL commands (add, delete, modify, and check)

One, the basic concept of the database

1.1 The composition of the database

data

  • Symbol record
  • Including numbers, text, graphics, images, sounds, file records, etc.
  • Store in a unified format in the form of "records"

table

  • Organize different records together to store specific data

database

  • A collection of tables is a warehouse for storing data
  • A collection of related data stored in a certain organization

1.2 Database Management System (DBMS)

  • It is a system software that realizes effective organization, management and access to database resources
  • Database establishment and maintenance function, data definition function, data manipulation function, database operation management function, communication function

1.3 Database System (DBS)

  • It is a man-machine system consisting of hardware, OS, database, DBMS, application software and database users
  • Users can operate the database through DBMS or applications
    Insert picture description here

2. Today's mainstream databases

Product (Company) operating system Features
SQL Server (product of Microsoft Corporation) For Windows operating system Simple and easy to use
Oracle (A product of Oracle Corporation) For all major platforms Safe, perfect, complicated operation
DB2 (product of IBM) For all major platforms Large, safe and complete
MySQL (acquired by Oracle) For all major platforms Free, open source, small size

3. Introduction to relational database

  • Relational database system is a database system based on relational model
  • The data structure of the relational model uses a simple and easy to understand two-dimensional data table.
    Each row is called a record, which is used to describe the information of an object.
    Each row is called a field, which is used to describe an attribute of the object.
  • The relational model can be represented by a simple "entity-relation-attribute"

3.1 Entity

Also called an instance, it corresponds to an "event" or "thing" that can be distinguished from other objects in the real world, Such as bank customers, bank accounts, etc.

3.2 Relationship

Correspondence between entity sets is called connection, also called relationship, Such as a "savings" relationship between bank customers and bank accounts

3.2 Properties

A certain characteristic of an entity, an entity can have multiple attributes
For example, each entity in the "bank customer" entity set has attributes such as name, address, and phone number

Fourth, the introduction of non-relational databases

Non-relational databases are also known as NoSQL (Not Only SQL)

Stored data is not based on the relational model and does not require a fixed table format
. Advantages of non-relational databases

The database can be read and written
with high concurrency Highly efficient storage and access to massive data The
database has high scalability and high availability

Five, MySQL database introduction

A popular open source relational database
product owned by Oracle. It
complies with the GPL agreement and can be used and modified for free.
Features

Excellent performance, stable service,
open source, no copyright restrictions, low cost
, multi-threaded, multi-user
based on C/S (client/server) architecture,
safe and reliable

Six, MySQL database basic command operations (add, delete, modify, check)

Commonly used data types

int Integer
float Single precision floating point 4 bytes 32 bits
double Double precision floating point 8 bytes 64 bits
char Fixed-length character type
varchar Variable length character type
text text
image image
decimal (5,2) 5 effective length numbers with 2 digits after the decimal point

SQL statement
SQL statements are used to maintain and manage databases, including functions such as data query, data update, access control, and object management.

SQL statement classification:

DDL Data definition language, used to create database objects, such as libraries, tables, indexes, etc.
DML Data manipulation language, used to manage the data in the table
DQL Data query language, used to find data records that meet the conditions from the data table
DCL Data control language, used to set or change database user or role permissions

View the database in the current server

SHOW DATABASES;						#大小写不区分,分号“;”表示结束

Insert picture description here
View the tables contained in the database

USE 数据库名;
SHOW TABLES;

Insert picture description here
View the structure of the table (fields)

USE 数据库名;
DESCRIBE [数据库名.]表名;
可缩写成:DESC 表名;

Insert picture description here

6.1 Increase

Create a new database

CREATE DATABASE 数据库名;

Insert picture description here
Create new table

CREATE TABLE 表名 (字段1 数据类型,字段2 数据类型[,...][,PRIMARY KEY (主键名)]);

Insert picture description here
Insert a new data record into the data table

INSERT INTO 表名(字段1,字段2[,...]) VALUES(字段1的值,字段2的值,...);

Insert picture description here

6.2 Delete

Delete the specified data table

DROP TABLE [数据库名.]表名;				#如不用USE进入库中,则需加上数据库名

Insert picture description here
Delete the specified database

DROP DATABASE 数据库名;

Insert picture description here
Delete the specified data record in the data table

DELETE FROM 表名 [WHERE 条件表达式];

Insert picture description here
Delete field

ALTER TABLE 表名 DROP 字段名;

Insert picture description here

6.3 Change

Modify and update data records in the data table

UPDATE 表名 SET 字段名1=字段值1,[字段名2=字段值2] [WHERE 条件表达式];

Insert picture description here
Insert picture description here
Modify table name

ALTER TABLE 旧表名 RENAME 新表名;

Insert picture description here
Expand table structure (add fields)

ALTER TABLE 表名 ADD address varchar(50) default '地址不详';

Insert picture description here
Modify the field (column) name, add a unique key

ALTER TABLE 表名 CHANGE 旧列名 新列名 数据类型 [unique key];

Insert picture description here

6.4 Check

SELECT 字段名1,字段名2[,...] FROM 表名 [WHERE 条件表达式];

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51613313/article/details/113178925