HTML基礎(chǔ)知識(26)【MySQL】【數(shù)據(jù)庫】

一、【數(shù)據(jù)庫】

1、關(guān)系型數(shù)據(jù)庫

大型:Oracle、DB2

中型:SQL Server、MySQL

小型:Access、SQLite等

2、非關(guān)系型數(shù)據(jù)庫:

Memcached、MongoDB、Redis

3、兩種數(shù)據(jù)庫陣營的區(qū)別

(1)關(guān)系型數(shù)據(jù)庫:安全(保存磁盤,基本不可能丟失),容易理解,比較浪費空間(二維表)

(2)非關(guān)系型數(shù)據(jù)庫:效率高,不安全(斷電丟失)

4、什么是關(guān)系型數(shù)據(jù)庫

是一種建立在關(guān)系模型(數(shù)學(xué)模型)上的數(shù)據(jù)庫

關(guān)系模型:一種所謂建立在關(guān)系上的模型

關(guān)系模型包含三個方面:

數(shù)據(jù)結(jié)構(gòu):用于解決數(shù)據(jù)存儲的問題,二維表(有行和列)

操作指令集合:所有SQL語句

完整性約束:表內(nèi)數(shù)據(jù)約束(字段與字段)、表與表之間約束(外鍵)

二、【MySQL】

-- 查看所有數(shù)據(jù)庫

show databases;

-- 連接認證

mysql -u root -p

-- 退出命令

exit、quit、\q

-- 創(chuàng)建數(shù)據(jù)庫

create database mydatabase charset utf8;

-- 創(chuàng)建關(guān)鍵字數(shù)據(jù)庫

create database `database` charset utf8;

-- 告訴服務(wù)器當(dāng)前中文的字符集是什么

set names gbk;

-- 創(chuàng)建中文數(shù)據(jù)庫

create database 中國 charset utf8;

-- 創(chuàng)建數(shù)據(jù)庫

create database informationtest charset utf8;

-- 查看以inforation_開始的數(shù)據(jù)庫(_需要被轉(zhuǎn)義)

show databaseslike 'information\_%';

show databaseslike 'information_%';-- 相當(dāng)于information%

-- 查看書數(shù)據(jù)庫的創(chuàng)建語句

showcreate database mydatabase;

showcreate database `database`;

-- 修改數(shù)據(jù)庫inforationest的字符集

alter database informationtest charset GBK;

-- 刪除數(shù)據(jù)庫

drop database 數(shù)據(jù)庫的名字;

-- 創(chuàng)建表

create table ifnot exists mydatabase.student(

-- 顯示的將student表放到mydatabase數(shù)據(jù)庫下

namevarchar(10),

gendervarchar(10),

numbervarchar(10),

ageint

)charset utf8;

-- 創(chuàng)建數(shù)據(jù)表

-- 進入數(shù)據(jù)庫

use mydatabase;

-- 創(chuàng)建表

create table class(

namevarchar(10),

roomvarchar(10)

)charset utf8;

-- 查看所有表

show tables;

-- 查看部分表

-- 查看以s結(jié)尾的表

show tableslike '%s';

-- 查看表的創(chuàng)建語句

showcreate table student;

showcreate table student\g

showcreate table student\G-- 將查到的結(jié)構(gòu)旋轉(zhuǎn)90度

-- 查看表結(jié)構(gòu)

desc class;

describe class;

show columnsfrom class;

-- 重命名表(student表—> my_student)

renametable studentto my_student;

-- 修改表選項:字符集

alter table my_student charset = GBK;

-- 給學(xué)生表增加ID,放到第一個位置

alter table my_studentadd column idint first;

-- 將學(xué)生表中的number學(xué)號字段標(biāo)出固定長度,且放到第二位(id之后)

alter table my_student modify numberchar(10) after id;

-- 修改學(xué)生表中的gender字段為sex

alter table my_student change gender sexvarchar(10);

-- 刪除學(xué)生表達中的age年齡字段

alter table my_studentdrop age;

-- 插入數(shù)據(jù)

insert into my_studentvalue

(1,'bc20190001','jim','male'),

(2,'bc20190001','lili','female')

;

-- 插入數(shù)據(jù):制定字段列表

insert into my_student(number,name,sex,id)values

('bc20190001','tom','male',3),

('bc20190001','zhong','male',4);

-- 查看所有數(shù)據(jù)

select *from my_student;

-- 查看指定字段、指定條件的數(shù)據(jù)

select id,number,sex,namefrom my_studentwhere id =1;

-- 更新數(shù)據(jù)

update my_studentset sex='female' where name ='jim';

-- 刪除數(shù)據(jù)

delete from my_studentwhere sex='male';

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容