免费高清特黄a大片,九一h片在线免费看,a免费国产一级特黄aa大,国产精品国产主播在线观看,成人精品一区久久久久,一级特黄aa大片,俄罗斯无遮挡一级毛片

分享

MySQL從入門到入魔(01)

 海擁 2021-11-30

數(shù)據(jù)庫

  • 學(xué)習(xí)數(shù)據(jù)庫就是學(xué)習(xí)如何和數(shù)據(jù)庫軟件進(jìn)行交流,SQL語言就是用于程序員和數(shù)據(jù)庫軟件進(jìn)行交流的語言.
  • DBMS:DataBaseManagementSystem 數(shù)據(jù)庫管理系統(tǒng)(數(shù)據(jù)庫軟件),包括:MySQL/Oracle/SQLServer,DB2,SQLite等
  • 常見DBMS介紹:
  1. MySQL:開源 Oracle公司產(chǎn)品,08年MySQL被Sun公司收購,09年Sun公司被Oracle, 原MySQL創(chuàng)始人離開Oracle創(chuàng)建新的數(shù)據(jù)庫MariaDB 市場占有率第一
  2. Oracle:閉源 Oracle公司產(chǎn)品, 性能最高價(jià)格最貴的數(shù)據(jù)庫. 市占率第二
  3. SQLServer:閉源 微軟公司產(chǎn)品,應(yīng)用在微軟的整套解決方案中 市占率第三
  4. DB2:閉源 IBM公司產(chǎn)品,應(yīng)用在IBM整套解決方案中.
  5. SQLite:輕量級(jí)數(shù)據(jù)庫,只提供基礎(chǔ)的增刪改成操作.安裝包幾十k,主要應(yīng)用在移動(dòng)設(shè)備和嵌入式設(shè)備中.
  • 網(wǎng)站的整套解決方案包括: 開發(fā)語言 操作系統(tǒng) web服務(wù)器軟件 數(shù)據(jù)庫軟件

  • 開源和閉源

  1. 開源:開發(fā)源代碼 免費(fèi), 盈利方式:通過賣服務(wù) , 會(huì)有程序員無償?shù)奶峁┥?jí)和維護(hù)
  2. 閉源:不開放源代碼 盈利方式:通過賣產(chǎn)品+賣服務(wù), 會(huì)有技術(shù)大拿攻擊,但是沒關(guān)系閉源產(chǎn)品的公司會(huì)養(yǎng)著一群人負(fù)責(zé)維護(hù)和升級(jí).

SQL語言

  • Structured Query Language:結(jié)構(gòu)化查詢語言, 用于程序員和數(shù)據(jù)庫軟件(DBMS)進(jìn)行交流

  • 如何連接數(shù)據(jù)庫軟件: 檢查mysql服務(wù)開啟 window鍵+r 輸入services.msc

  • 開始菜單中找到Mysql/MariaDB文件夾 里面的 Mysql Client 打開后直接輸入密碼

  • 如果是linux或mac系統(tǒng) 先打開終端 在終端中輸入 mysql -u用戶名 -p回車 回車后輸入密碼 回車

  • 斷開連接: 關(guān)閉窗口 或執(zhí)行 exit;

      Access denied for user 'root'@'localhost' (using password: YES)   密碼錯(cuò)誤
    

數(shù)據(jù)庫相關(guān)SQL語句

  • 往數(shù)據(jù)庫軟件中保存數(shù)據(jù),需要先建庫再建表,最后再操作表里面的數(shù)據(jù)
  1. 查詢所有數(shù)據(jù)庫
  • 格式: show databases;
  1. 創(chuàng)建數(shù)據(jù)庫
  • 格式: create database 數(shù)據(jù)庫名; 使用默認(rèn)字符集創(chuàng)建數(shù)據(jù)
create database db1;
  • 指定字符集格式: create database 數(shù)據(jù)庫名 character set utf8/gbk;
create database db2 character set utf8;
create database db3 character set gbk;
  1. 查看數(shù)據(jù)庫詳情
  • 格式: show create database 數(shù)據(jù)庫名;
show create database db1;
  1. 刪除數(shù)據(jù)庫
  • 格式: drop database 數(shù)據(jù)庫名;
drop database db4;
  1. 使用數(shù)據(jù)庫
  • 對(duì)表和數(shù)據(jù)進(jìn)行操作時(shí)必須先使用了數(shù)據(jù)庫才可以 不然會(huì)報(bào)錯(cuò)
  • 格式: use 數(shù)據(jù)庫名;
use db1;

數(shù)據(jù)庫相關(guān)練習(xí):

  1. 分別創(chuàng)建mydb1和mydb2 第一個(gè)字符集utf8 第二個(gè)gbk
create database mydb1 character set utf8;
create database mydb2 character set gbk;
  1. 查詢所有數(shù)據(jù)庫檢查是否創(chuàng)建成功
show databases;
  1. 分別查詢兩個(gè)數(shù)據(jù)庫的字符集是否成功
    show create database mydb1;
show create database mydb2;
  1. 先使用mydb1 再使用mydb2
    use mydb1;
use mydb2;
  1. 刪除兩個(gè)數(shù)據(jù)庫
drop database mydb1;
drop database mydb2;

表相關(guān)的SQL

  • 操作表時(shí)一定保證已經(jīng)使用了某個(gè)數(shù)據(jù)庫 不然會(huì)報(bào)以下錯(cuò):
    ERROR 1046 (3D000): No database selected
  1. 創(chuàng)建表
  • 格式: create table 表名(字段名 字段類型,字段名 字段類型);
create table student(name varchar(10),age int);
  • 指定字符集格式: create table 表名(字段名 類型,字段名 類型) charset=utf8/gbk;
create table person(name varchar(10),gender varchar(5))charset=gbk;
  1. 查詢所有表
  • 格式: show tables;
  1. 查詢表詳情
  • 格式: show create table 表名;
show create table person;
  1. 查看表字段
  • 格式: desc 表名;
desc student;
  1. 刪除表
  • 格式: drop table 表名:
drop table student;
  1. 修改表名
  • 格式: rename table 原名 to 新名;
rename table person to t_person;
  1. 添加表字段
  • 最后添加格式: alter table 表名 add 字段名 類型;
  • 最前面添加:alter table 表名 add 字段名 類型 first;
  • 在某個(gè)字段后面添加 alter table 表名 add 字段名 類型 after xxx;
alter table t_person add salary int;
alter table t_person add id int first;
alter table t_person add age int after name;
  1. 刪除表字段
  • 格式: alter table 表名 drop 字段名;
alter table t_person drop salary;
  1. 修改表字段
  • 格式: alter table 表名 change 原名 新名 新類型;
alter table t_person change age salary int;

表相關(guān)SQL語句回顧

  1. 創(chuàng)建 create table t1(name varchar(10),age int)charset=utf8;
  2. 查詢所有 show tables;
  3. 查詢表詳情 show create table t1;
  4. 查詢表字段 desc t1
  5. 刪除表 drop table t1;
  6. 修改表名 rename table t1 to t2;
  7. 添加表字段 alter table t1 add salary int first/ after xxx;
  8. 刪除表字段 alter table t1 drop salary;
  9. 修改表字段 alter table t1 change 原名 新名 新類型;

表相關(guān)練習(xí)題:

  • 創(chuàng)建數(shù)據(jù)庫mydb1 字符集utf8 并使用該數(shù)據(jù)庫
create database mydb1 character set utf8;
use mydb1;
  • 在mydb1中創(chuàng)建員工表emp 字段有name 表字符集也是utf8
create table emp(name varchar(10)) charset=utf8;
  • 添加表字段age在最后
alter table emp add age int;
  • 添加id字段在最前面
alter table emp add id int first;
  • 添加性別gender在name后面
alter table emp add gender varchar(5) after name;
  • 修改gender為工資sal
alter table emp change gender sal int;
  • 刪除age字段
alter table emp drop age;
  • 修改表名為t_emp
rename table emp to t_emp;
  • 刪除t_emp表
drop table t_emp;
  • 刪除數(shù)據(jù)庫
drop database mydb1;

###數(shù)據(jù)相關(guān)SQL

  • 執(zhí)行數(shù)據(jù)相關(guān)的SQL 必須保證已經(jīng)使用了某個(gè)數(shù)據(jù)庫,并且存在數(shù)據(jù)所對(duì)應(yīng)的表格
create database mydb2 character set utf8;
use mydb2;
create table person(name varchar(10),age int)charset=utf8;
  1. 插入數(shù)據(jù)
  • 全表插入格式(要求值的數(shù)量和順序必須和表字段一致): insert into 表名 values(值1,值2,值3);
insert into person values('Tom',18);
  • 指定字段插入格式(要求值的數(shù)量和順序必須和指定的一致): insert into 表名(字段名1,字段名2)values(值1,值2);
insert into person(name)values('Jerry');
  • 批量插入數(shù)據(jù)格式: 在values后面寫多組值即可f
    insert into person values('Lucy’,20),('Lily’,21);
insert into person(name)values('zhangsan'),('lisi');
  • 插入中文:
insert into person values('劉德華',30);
如果執(zhí)行以上代碼出現(xiàn)錯(cuò)誤提示,提示里面包含16進(jìn)制的錯(cuò)誤信息 執(zhí)行以下SQL
set names gbk;
  1. 查詢數(shù)據(jù)
  • 格式: select 字段信息 from 表名 where 條件;
  • 舉例:
    查詢person表中所有的名字
    select name from person;
    查詢person表中年齡大于20的名字和年齡
    select name,age from person where age>20;
    查詢person表中所有數(shù)據(jù)的所有字段信息
    select * from person;
  1. 修改數(shù)據(jù)
  • 格式: update 表名 set 字段名=xxx,字段名=xxx where 條件;
  • 舉例:
update person set age=8 where name='Tom';
update person set age=10 where age is null;
  1. 刪除數(shù)據(jù)
  • 格式: delete from 表名 where 條件;
  • 舉例:
    1. 刪除Tom
delete from person where name='Tom';
2. 刪除年齡小于20歲的
delete from person where age<20;
3. 刪除所有數(shù)據(jù)
delete from person;

增刪改查回顧:

  1. 插入數(shù)據(jù) insert into 表名 values(值1,值2);
  2. 查詢數(shù)據(jù) select 字段信息 from 表名 where 條件;
  3. 修改數(shù)據(jù) update 表名 set 字段名=xxx where 條件;
  4. 刪除數(shù)據(jù) delete from 表名 where 條件;

數(shù)據(jù)類型

  1. 整數(shù)類型: int(m)和bigint(m) bigint等效java中的long, m代表顯示長度 需要結(jié)合zerofill關(guān)鍵字使用
create table t1(name varchar(10),age int(10) zerofill);
insert into t1 values('Tom',18);
select * from t1;
  1. 浮點(diǎn)數(shù): double(m,d) m代表總長度 d代表小數(shù)長度 58.234 m=5 d=3 ,超高精度的浮點(diǎn)數(shù)decimal(m,d)只有涉及超高精度運(yùn)算時(shí)使用.
  2. 字符串:
  • char(m): 固定長度 m=10 存"abc" 占10,執(zhí)行效率略高 最大255
  • varchar(m):可變長度 m=10 存"abc" 占3,更節(jié)省存儲(chǔ)空間, 最大65535 超過255建議使用text
  • text(m):可變長度,最大值65535.
  1. 日期:
  • date: 只能保存年月日
  • time: 只能保存時(shí)分秒
  • datetime:保存年月日時(shí)分秒,默認(rèn)值是null,最大值9999-12-31
  • timestamp:時(shí)間戳(距離1970年毫秒數(shù)),保存年月日時(shí)分秒,默認(rèn)值當(dāng)前系統(tǒng)時(shí)間,最大值2038-1-19
  • 舉例:
create table t_date(t1 date,t2 time,t3 datetime,t4 timestamp);
insert into t_date values('2020-1-18',null,null,null);
insert into t_date values(null,'17:35:18','2020-3-17 12:30:23',null);

Java、Python、算法知識(shí)體系 | PPT、簡歷模板 | 游戲源碼 | IT行業(yè)趣味資訊 | 裝機(jī)必備軟件

關(guān)注下方公號(hào)回復(fù)【資料】獲取 👇🏻👇🏻👇🏻

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多