數(shù)據(jù)庫:DataBase,簡稱DB.按照一定格式存儲數(shù)據(jù)的一些文件的組合苍日。存儲數(shù)據(jù)的倉庫把敞,實際上就是一堆文件圾叼。這些文件存儲了特定格式的數(shù)據(jù)朱庆。
數(shù)據(jù)庫管理系統(tǒng):DataBaseManagementSystem簡稱DBMS盛泡。
數(shù)據(jù)庫管理系統(tǒng)是專門用來管理數(shù)據(jù)庫中的數(shù)據(jù)的,數(shù)據(jù)管理系統(tǒng)可以對數(shù)據(jù)庫當中的數(shù)據(jù)進行增刪改查娱颊。
常見的數(shù)據(jù)庫管理系統(tǒng):MySQL Oracle MS SqlServer DB2 sybase等....
SQL:結構化查詢語言
程序員需要學習SQL語句傲诵,編寫Sql語句,然后DBMS負責執(zhí)行SQL語句箱硕,最終來完成數(shù)據(jù)庫的增刪改查操作拴竹。
SQL是一套標準,程序員主要學習的就是SQL語句剧罩,這個SQL在mysql中可以使用栓拜,同時在Oracle中也可以使用,在DB2中也可以使用。
三者直接的關系幕与?
DBMS——執(zhí)行——>SQL-—操作—>DB
mysql常用命令(不區(qū)分大小寫):
退出:exit
查看MySQL中有哪些數(shù)據(jù)庫挑势?show datebases;
+--------------------+| Database? ? ? ? ? |+--------------------+| information_schema || mysql? ? ? ? ? ? ? || performance_schema || sys? ? ? ? ? ? ? ? |+--------------------+
mysql默認自帶4個數(shù)據(jù)庫。怎么選擇使用某個數(shù)據(jù)庫呢纽门?
use sys;? 表示正在使用叫sys的數(shù)據(jù)庫薛耻。
怎么創(chuàng)建數(shù)據(jù)庫呢?
create database bjpowernode(名字);創(chuàng)建數(shù)據(jù)庫+show databases;展示數(shù)據(jù)庫+ use (名字);
查看數(shù)據(jù)庫下有哪些表: show tables;
關于SQL語句的分類?
DQL: (DataQueryLanguage): 數(shù)據(jù)查詢語言(凡是帶有select關鍵字的都是查詢語句)
DML: ? (Data Manipulation Language) 數(shù)據(jù)操作語言(凡是對 表中的數(shù)據(jù)進行增刪改的)
? insert(增)? delete(刪)? ? update(改)
DDL: (Data Definition Language) 數(shù)據(jù)定義語言(凡是帶有creat drop alter的都是DDL赏陵,DDL主要 ? 操作的是 表的結構饼齿。不是表中的數(shù)據(jù) )
creat(新建) drop(刪除) alter(修改)
? 這個增刪改和DML不同,主要是對表結構進行操作
TCL: (Transaction? Control Language) 事務控制語言:
? 事務提交:commit;
事務回滾:rollback;
DCL: (Data Control Language) 數(shù)據(jù)控制語言:
授權:grant
? 撤銷權限:revoke
本地登錄:
C:\WINDOWS\system32>mysql -uroot -p+密碼mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.? Commands end with ; or \g.Your MySQL connection id is 11Server version: 8.0.29 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
數(shù)據(jù)庫中最基本的單元是表:table
數(shù)據(jù)庫中是以表格形式表示數(shù)據(jù)蝙搔。因為比較直觀
任何一張表都有行和列:
行(row):被稱為數(shù)據(jù)/記錄
列(column):被稱為字段缕溉。每一個字段都有 字段名 數(shù)據(jù)類型 約束等屬性。
字段名就是一個普通的名字吃型。
數(shù)據(jù)類型:字符串 數(shù)字 日期等证鸥。
約束:約束也有很多,其中一個叫做唯一性約束勤晚。這種約束添加之后枉层,該字段中的數(shù)據(jù)不能重復
7.5
導入數(shù)據(jù):mysql> source? +數(shù)據(jù)路徑
注意:路徑中不能有中文
查看表中的數(shù)據(jù):? select * from 表名
不看表中的數(shù)據(jù)? 只看表中的結構:
desc 表名;
常用命令
select version(); 查看數(shù)據(jù)庫版本號
select database; 查看當前使用的是哪個數(shù)據(jù)庫