数据库基础
# 数据库的概念
数据库是按照数据结构来组织、存储和管理数据的仓库,是一个长期存储在计算机内的、有组织的、可共享的、统一管理的大量数据的集合。
数据库的存储介质:
- 磁盘
- 内存
# 连接服务器
mysql -h 127.0.0.1 -P 3306 -u root -p
1
-h
: 表示你要连接的MySQL服务器所在的主机,127.0.0.1表示本主机。-P
: 表示你要连接的MySQL服务器所对应的端口号,一般默认是3306。-u
: 表示用哪一个用户连接MySQL服务器,root表示超级用户。-p
: 表示该用户对应的密码,密码可以直接跟在-p后面,也可以回车后输入
# SQL分类
SQL(Structured Query Language,结构化查询语言)是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统。
SQL语句可分为如下三类:
- DDL(Data Definition Language)数据定义语言,用来维护存储数据的结构。比如create语句、drop语句、alter语句等。
- DML(Data Manipulation Language)数据操作语言,用来对数据进行操作。比如insert语句、delete语句、update语句等。
- DCL(Data Control Language)数据控制语言,主要负责权限管理和事务。比如grant语句、revoke语句、commit语句。
说明一下: DML中又单独分了一个DQL(Data Query Language)数据查询语言,比如select语句、from语句、where语句等。
# 存储引擎
存储引擎就是数据库管理系统如何存储数据、如何为存储的数据建立索引、如何更新数据、如何查询数据等技术的实现方法,MySQL中的存储引擎是插件式的存储引擎,它可以支持多种存储引擎。
查询存储引擎:
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ndbcluster | NO | Clustered, fault-tolerant tables | NULL | NULL | NULL |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| ndbinfo | NO | MySQL Cluster system information storage engine | NULL | NULL | NULL |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
上次更新: 2025/03/14, 11:20:46