Command operation of MySQL database

1. The basic concept of Mysql database

1. Data

  • Symbolic records describing things
  • Including numbers, text, graphics, images, sounds, file records, etc.
  • Stored in a uniform format as "records"

2. table

  • group different records together
  • used to store specific data

3. Database

  • A collection of tables is a warehouse for storing data
  • A collection of interrelated data stored in an organized manner
  • It is a warehouse that organizes, stores and manages data according to the data structure

insert image description here

4. Database Management System (DBMS)

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

5. Database system

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

insert image description here

2. Mysql database system development history

first generation database

  • Since the 1960s, the first generation of database systems came out
  • It is a database system with hierarchical model and network model
  • Provides strong support for unified management and data sharing

second generation database

  • In the early 1970s, the second generation of databases - relational databases began to appear.
  • In the early 1980s, IBM's relational database system DB2 came out and began to gradually replace the hierarchical and network model databases, becoming the mainstream of the industry.
  • So far, relational database systems still occupy the main position of database applications

third generation database

  • Since the 1980s, new database systems adapted to different fields have emerged continuously
  • An object-oriented database system with strong practicability and wide adaptability.
  • In the late 1990s, a situation in which multiple database systems jointly supported applications was formed.
  • Some new elements are added to mainstream database systems
    例如,Oracle支持的“关系-对象”数据库模型

3. Present mainstream Mysql database introduction

SQL Server (Microsoft product)

  • For Windows OS
  • simple and easy to use
    insert image description here

Oracle (an Oracle product)

  • For all major platforms
  • Safe, perfect, complex operation
    insert image description here

DB2 (IBM product)

  • For all major platforms
  • Large, safe and complete
    insert image description here

MySQL (acquired by Oracle Corporation)

  • Free, open source, small size
    insert image description here

4. Relational database

  • A relational database system is a database based on the relational model
  • The data structure of the relational model of the system uses an easy-to-understand two-dimensional data table
  • The relational model can be represented by a simple "entity-relationship" (ER) diagram
  • The ER diagram contains three elements: entity (data object), relationship and attribute.
    insert image description here
    Table 1: Represents the entity set as a bank customer (customer code is a unique identifier for distinguishing customer entities)
    insert image description here
    Table 2: Represents the entity set as a bank account (account coded as a unique identifier for distinguishing account entities)
    insert image description here

Table 3: Indicates the establishment of savings relationships between bank accounts and bank customers (the savings code is a unique identifier for distinguishing each savings relationship). The
insert image description here
storage structure of the relational database is a two-dimensional table:

in each two-dimensional table

  • Each row is called a record, which is used to describe the information of an object
  • Each column is called a field and is used to describe a property of the object

Relational database applications:

Name database Application examples
Oracle,MySQL 12306 User Information System
SQLServer,Sybase Taobao account system
Informix,access China Unicom mobile phone number information system
DB2,FoxPRO Bank User Account System
PostgreSQL Website user information system

5. Introduction to non-relational databases

1. Non-relational databases are also called NoSQL (Not Only SQL)
2. Data storage is not based on relational models and does not require a fixed table format
3. Advantages of non-relational databases

  • The database can be read and written with high concurrency
  • Efficient storage and access to massive data
  • Database with high scalability and high availability

Commonly used non-relational databases: Redis, mongoDB, etc.

Non-relational database NoSQL storage structure key-value pair k/v key/value
cache type Redis Memcached
document type MongoDB
search type ElasticSearch
time series type Prometheus InfluxDB

Commonly used data types:

int : 整型无符号[0,2^32-1],有符号[-2^31,2^31-1]
float :单精度浮点 4字节32位
double : 双精度浮点 8字节64位
char : 固定长度的字符类型
varchar :可变长度的字符类型文本
text :文本
image : 图片
decimal(5,2):5个有效长度数字,小数点后面

Common Database Structure

1. View the databases in the current server

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

insert image description here
2. View the tables contained in the database

USE 数据库名;
方法一:SHOW TABLES;
方法二:show tables from mysql;

insert image description here
insert image description here
3. View the structure of the table (fields)

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

insert image description here
insert image description here
SQL statement
SQL statement is used to maintain and manage the database, including data query, data update, access control, object management and other functions.

SQL language classification, divided into 4 types
DDL: Data Definition Language, used to create database objects, such as libraries, tables, indexes, etc.
DML: Data Manipulation Language, used to manage data in tables
DQL: Data Query Language, used for Find eligible data records from the data table
DCL: data control language, used to set or change database user or role permissions

6. MySQL installation method

1. Create a new database

create database 数据库名;
insert image description here

2. Create a new table

mysql > create table 表名 
      >(字段1 数据类型,
      > 字段2 数据类型【......
      >【,primary key(主键名)】);
主键一般选择能代表唯一性的字段不允许取空值(NULL),一个表只能有一个主键。

insert image description here
insert image description here

3. Delete the specified database

drop database

insert image description here

4. Delete the specified data table

insert image description here

5. Insert new data records into the data table

insert image description here

6. Modify and update the data records in the data table

insert image description here

7. Delete the specified data record in the data table

insert image description here

8. View the data records in the table

insert image description here

9. Modify the table name

insert image description here

10. Extend the table structure (add fields)

insert image description here

11. Modify the field name and add a unique key

insert image description here

Guess you like

Origin blog.csdn.net/Wanghwei17/article/details/131287117