先講數(shù)據(jù)庫 -- mysql 、redis、MongoDB
爬蟲
今天的內(nèi)容:mysql一 基本操作
注意事項(xiàng):
1.安裝 : 自己安裝,有問題可以問老師、可以自己找辦法解決
2.上課:先講知識點(diǎn)再回答問題
3.預(yù)習(xí):很重要
4.課外:課外知識請私聊老師
mysql一 基本操作:
1.數(shù)據(jù)庫分類:
關(guān)系型數(shù)據(jù)庫:mysql、oracle
非關(guān)系型數(shù)據(jù)庫:mongodb、redis
2.e-r模型
實(shí)體:現(xiàn)實(shí)世界中任何可以被認(rèn)知、區(qū)分的事物
屬性:實(shí)體所具有的特性
關(guān)系:描述兩個實(shí)體之間對應(yīng)規(guī)則
一對一
一對多
多對多
3. 命令:
mysql -uroot -p: u代表用戶名 p是密碼
安裝了虛擬機(jī)的同學(xué),mysql的密碼是:mysql
連接mysql,切換路徑:
cmd中切換路徑: 比如切換到D:\mysql-8.0.21-winx64\bin路徑下
d: 這個命令是切換到D盤
cd 路徑 切換到對應(yīng)的目錄下
庫級操作:
語句后面記得加;
顯示所有數(shù)據(jù)庫:show databases;
創(chuàng)建新的數(shù)據(jù)庫:create database 數(shù)據(jù)庫名 charset=utf8;
查詢當(dāng)前使用的數(shù)據(jù)庫:select database();
切換數(shù)據(jù)庫:use 數(shù)據(jù)庫名;
刪除數(shù)據(jù)庫:drop database 數(shù)據(jù)庫名;
表級操作:
顯示所有數(shù)據(jù)表: show tables;
創(chuàng)建表:create table 表名( id int, name varchar(20));
顯示建表信息:show create table 表名;
查看表結(jié)構(gòu):desc 表名;
更改表名:rename table 原名 to 新名;
刪除表: drop table 表名;
數(shù)據(jù)操作: 增刪改查
插入數(shù)據(jù):
全字段:insert into test2 value(1, '工科僧');
指定字段:insert into test2(id, name) values(2, 'DY');
多行:insert into test2 values(), ();
查詢數(shù)據(jù):
select * from 表名;
字段查詢: select id from test2;
條件查詢:select * from test2 where id=3;
更新數(shù)據(jù):
update test2 set name='大海星辰' where name='工科僧'
update test2 set id=9; 所有id都會變成9
刪除數(shù)據(jù):
指定刪除數(shù)據(jù); delete from test2 where name='九歌的';
刪除表中全部數(shù)據(jù):delete from test2; 表結(jié)構(gòu)還在