亚洲精品中文免费|亚洲日韩中文字幕制服|久久精品亚洲免费|一本之道久久免费

<optgroup id="cczp1"><ruby id="cczp1"><cite id="cczp1"></cite></ruby></optgroup>
  • <acronym id="cczp1"></acronym>
    <acronym id="cczp1"><option id="cczp1"><ol id="cczp1"></ol></option></acronym>
    <delect id="cczp1"></delect>
    <center id="cczp1"></center>
    <delect id="cczp1"></delect><em id="cczp1"><button id="cczp1"><blockquote id="cczp1"></blockquote></button></em>
    1. <optgroup id="cczp1"><td id="cczp1"><dfn id="cczp1"></dfn></td></optgroup>

      史上最全mysql操作語(yǔ)句吐血整理

      mysql的操作語(yǔ)句共分為四大類,分別是:

      DDL 數(shù)據(jù)定義語(yǔ)言 (Data Definition Language) ,例如:建庫(kù),建表

      DML 數(shù)據(jù)操縱語(yǔ)言(Data Manipulation Language) ,例如:對(duì)表中的數(shù)據(jù)進(jìn)行增刪改操作

      DQL 數(shù)據(jù)查詢語(yǔ)言(Data Query Language) ,例如:對(duì)數(shù)據(jù)進(jìn)行查詢

      DCL 數(shù)據(jù)控制語(yǔ)言(Data Control Language), 例如:對(duì)用戶權(quán)限進(jìn)行設(shè)置

      1.DDL

      創(chuàng)建數(shù)據(jù)庫(kù):create database db1;

      查詢當(dāng)前所屬庫(kù):select database();

      進(jìn)入某個(gè)庫(kù):use 庫(kù)名;

      不存在則創(chuàng)建數(shù)據(jù)庫(kù):create database if not exists db2;

      查詢數(shù)據(jù)庫(kù)并指定字符集:create database db3 default character set gbk;

      查詢某個(gè)庫(kù)的字符集:show create database db2;

      查看當(dāng)前mysql使用的字符集:show variables like 'character%';

      建表:

      CREATE TABLE man(

      id bigint(20) zerofill auto_increment not null comment '主鍵ID',

      name varchar(255) default null comment '名稱',

      sex tinyint(4) default null comment '性別',

      age tinyint(3) default null comment '年齡',

      unique key (id)

      )engine=innodb charset=utf8;

      create table 新表名 as select * from 舊表名 where 1=2;

      create table 新表名 like 舊表名;

      查看數(shù)據(jù)庫(kù)中的所有表:show tables;

      查看表結(jié)構(gòu):desc 表名

      查看創(chuàng)建表的sql語(yǔ)句:show create table 表名;

      修改表名:rename table 舊表名 to 新表名;

      添加列:alter table person add name varchar(50) comment '姓名' after id;

      修改列類型:alter table person modify name varchar(100);

      修改列名:alter table person change name person_name varchar(100);

      刪除列:alter table person drop name;

      刪除表:drop table person;

      判斷表是否存在,存在則刪除:drop table if exists person;

      2.DML

      插入表數(shù)據(jù):

      insert into person (name,age,sex,created_time) values ('張三',20,'男','2022-01-01');

      insert into person values ('張三',20,'男','2022-01-01'); //對(duì)應(yīng)所有字段

      將一張表的數(shù)據(jù)復(fù)制到另一張表中:

      insert into 表名1(字段名1,字段名2) select 字段名1,字段名2 from 表名2;

      新建表復(fù)制表結(jié)構(gòu)和數(shù)據(jù):

      create table 表名1 as select 字段名1,字段名2 from 表名2;

      一次性插入多條數(shù)據(jù):

      insert into 表名 (字段名) values (對(duì)應(yīng)值1),(對(duì)應(yīng)值2),(對(duì)應(yīng)值3);

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

      update 表名 set 字段名1=值1 where 字段名=值;

      update 表名 set 字段名1=值1,字段名2=值2 where 字段名=值;

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

      delete from 表名 where 字段名=值;

      truncate table 表名;

      delete from 表名;

      drop table 表名;

      三者區(qū)別:

      delete記錄刪除操作,可以回退,不釋放空間,truncate不記錄刪除操作,不能回退,drop會(huì)刪除整張表,釋放空間,刪除速度drop>truncate>delete

      3.DQL

      where精確條件:

      select * from employee where ename='張三';

      select * from employee where sex != 1;

      select * from employee where sal <> 8000;

      select * from employee where sal > 10000;

      where模糊條件:

      select * from employee where ename like '%三%';

      where范圍查詢:

      select * from employee where sal between 5000 and 10000;

      where離散查詢:

      select * from employee where ename in ('張三','李四','王二','周五');

      去重:

      select distinct(ename) from employee;

      聚合函數(shù):

      統(tǒng)計(jì):select count(*) from employee;

      求和:select sum(sal) from employee;

      最大值:select * from employee where sal= (select max(sal) from employee);

      平均值:select avg(sal) from employee;

      最小值:select * from employee where sal= (select min(sal) from employee);

      字符串連接:select concat(ename,' 在 ',dept) as info from employee;

      group by(分組):

      select dept,count(*) from employee group by dept;

      select dept,job,count(*) from employee group by dept,job;

      select job,count(*) from employee group by job;

      having(對(duì)查詢的結(jié)果進(jìn)行篩選,一般用于group by之后):

      select job,count(*) from employee group by job having job ='文員';

      select dept,job,count(*) from employee group by dept,job having count(*)>=2;

      select dept,job,count(*) as 總數(shù) from employee group by dept,job having 總數(shù)>=2;

      order by(排序):

      select * from employee order by sal;

      select dept,job,count(*) as 總數(shù) from employee group by dept,job having 總數(shù)>=2 order by dept desc;

      select dept,job,count(*) as 總數(shù) from employee group by dept,job having 總數(shù)>=2 order by dept asc;

      執(zhí)行順序:where —- group by —– having —— order by

      limit:

      select * from employee limit 4,5; //從第4條開始,取出5條

      exists:

      如果exists后的內(nèi)層查詢能查出數(shù)據(jù),則返回 TRUE 表示存在;為空則返回 FLASE則不存在

      select * from dept a where exists (select 1 from employee b where a.dept=b.dept); //查詢出公司有員工的部門的詳細(xì)信息

      select * from dept a where not exists (select 1 from employee b where a.dept=b.dept); //查詢出公司沒有員工的部門的詳細(xì)信息

      左連接(left join)與右連接(right join):

      都屬于外連接,左連接表示左邊的表數(shù)據(jù)全部顯示,右邊表只顯示符合條件的記錄,沒有記錄用null代替,右連接則相反。

      //列出部門員工和這些部門的員工信息

      select a.dname,b.* from dept a left join employee b on a.dept=b.dept;

      select b.dname,a.* from employee a right join dept b on b.deptnu=a.deptnu;

      內(nèi)連接與聯(lián)合查詢:

      內(nèi)連接:獲取兩個(gè)表中字段匹配關(guān)系的記錄

      eg:查出張三所在部門的地址:

      select a.addr from dept a inner join employee b on a.dept=b.dept and b.ename='張三';

      select a.addr from dept a,employee b where a.dept=b.dept and b.ename='張三';

      聯(lián)合查詢:把多個(gè)查詢語(yǔ)句的查詢結(jié)果結(jié)合在一起,UNION去除重復(fù),UNION ALL不去重

      eg:對(duì)銷售員的工資從低到高排序,而文員的工資從高到低排序

      (select * from employee a where a.job = '銷售員' order by a.sal limit 999999 ) union (select * from employee b where b.job = '文員' order by b.sal desc limit 999999);

      4.DCL

      查看root用戶可以在哪臺(tái)機(jī)器登錄:select user,host from mysql.user where user='root';

      修改mysql庫(kù)里邊的user表:update mysql.user set host='localhost' where user='root';

      刷新權(quán)限:flush privileges;

      修改用戶密碼:

      set password for [email protected] = password('root');

      mysqladmin -urootmysqladmin -uroot -proot password;

      update mysql.user set authentication_string=password('root') where user='root' and host='localhost';

      忘記密碼怎么辦:

      第一步:修改配置文件my.cnf (默認(rèn)在/etc/my.cnf),在[mysqld]下面加上 skip-grant-tables (跳過權(quán)限的意思)

      第二步:重啟mysql服務(wù)

      第三步:mysql -uroot -p 無需密碼登錄進(jìn)入

      第四步:修改密碼

      限制用戶權(quán)限:

      授權(quán):

      grant 權(quán)限1,權(quán)限2….. on 數(shù)據(jù)庫(kù)對(duì)象 to '用戶'@'host' identified by 'password';

      對(duì)現(xiàn)有用戶進(jìn)行授權(quán):對(duì)現(xiàn)有用戶xxx授予所有庫(kù)所有表所有權(quán)限:

      grant all privileges on *.* to 'xxx';

      對(duì)沒有的用戶進(jìn)行授權(quán):創(chuàng)建一個(gè)新用戶XXX授予test庫(kù)的所有權(quán)限,登錄密碼123456,任何一臺(tái)主機(jī)登錄:

      grant all privileges on test.* to 'XXX'@'%' identified by '123456';

      對(duì)沒有的用戶進(jìn)行授權(quán):創(chuàng)建一個(gè)新用戶XXX授予test庫(kù)的employee表 查與修改權(quán)限,登錄密碼123456,任何一臺(tái)主機(jī)登錄:

      grant select,update on test.employee to 'XXX'@'%' identified by '123456'

      對(duì)沒有的用戶進(jìn)行授權(quán):對(duì)用戶XXX授予test庫(kù)的employee表insert 權(quán)限,登錄密碼123456,任何一臺(tái)主機(jī)登錄:

      grant insert on test.employee to 'XXX'@'%' identified by '123456';

      回收:

      回收XXX用戶的所有權(quán)限(注意:并沒有回收它的登錄權(quán)限):

      revoke all privileges on *.* from 'XXX' @ '%';

      flush privileges;

      回收XXX用戶的所有權(quán)限(并回收它的登錄權(quán)限)

      delete from mysql.user where user='xxx';

      flush privileges;

      回收XXX用戶對(duì)test庫(kù)的employee的查與修改權(quán)限

      revoke select,update on test.employee from 'xxx'@'%';

      flush privileges;

      史上最全mysql操作語(yǔ)句吐血整理

      鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場(chǎng),版權(quán)歸原作者所有,如有侵權(quán)請(qǐng)聯(lián)系管理員(admin#wlmqw.com)刪除。
      用戶投稿
      上一篇 2022年6月28日 14:55
      下一篇 2022年6月28日 14:55

      相關(guān)推薦

      • ios手游模擬器(手游模擬器ios)

        本文主要講的是ios手游模擬器,以及和手游模擬器ios相關(guān)的知識(shí),如果覺得本文對(duì)您有所幫助,不要忘了將本文分享給朋友。 哪個(gè)iOS模擬器能多開手游賬號(hào)?可以推薦個(gè)好用的模擬器給我嗎…

        2022年11月27日
      • 短視頻策劃內(nèi)容的3個(gè)要點(diǎn)(短視頻策劃內(nèi)容怎么做)

        短視頻在制作時(shí),內(nèi)容框架非常重要。如果直奔主題,然后結(jié)束,聚卓告訴你,這樣的短視頻已經(jīng)過時(shí)了。現(xiàn)在的短視頻需要框架的,但不是任何框架,它需要一種易于理解和消化的框架。而且,現(xiàn)在大多…

        2022年11月27日
      • 美團(tuán)第三季度實(shí)現(xiàn)營(yíng)收626億元,即時(shí)配送訂單量增至50億筆

        新京報(bào)訊(記者秦勝南)11月25日,美團(tuán)發(fā)布業(yè)績(jī)公告顯示,第三季度營(yíng)收為626億元,較去年同比增長(zhǎng)28.2%,凈利潤(rùn)為12.2億元。第三季度,美團(tuán)即時(shí)配送訂單數(shù)增長(zhǎng)至50億筆。截至…

        2022年11月27日
      • 個(gè)人怎么做抖音帶貨(個(gè)人做抖音帶貨能賺錢嗎)

        抖音如今是大家很熟悉的短視頻平臺(tái),不過現(xiàn)在的抖音卻不只是短視頻那么簡(jiǎn)單,它的功能非常豐富,其中一個(gè)就是可以帶貨,相信很多小伙伴都有在抖音上買過東西,抖音如今的變現(xiàn)能力也是不容小覷的…

        2022年11月25日
      • 小紅書平臺(tái)的一些機(jī)制及玩法詳解(小紅書玩法有哪些)

        關(guān)于小紅書 一:小紅書平臺(tái)的一些機(jī)制 1. 筆記內(nèi)容的CES評(píng)分機(jī)制 2. 筆記流量入口與長(zhǎng)尾效應(yīng) 二:小紅書優(yōu)質(zhì)筆記的特點(diǎn)(分維度、類型分析) 1.筆記的本身架構(gòu)組成 維度 2.…

        2022年11月25日
      • 什么是推廣cpa一篇文章帶你看懂CPA推廣渠道

        CPA渠道 CPA指的是按照指定的行為結(jié)算,可以是搜索,可以是注冊(cè),可以是激活,可以是搜索下載激活,可以是綁卡,實(shí)名認(rèn)證,可以是付費(fèi),可以是瀏覽等等。甲乙雙方可以根據(jù)自己的情況來定…

        2022年11月25日
      • 百度關(guān)鍵詞快速排名的4大原理解析(百度怎么刷關(guān)鍵詞)

        近期百度公告驚雷算法2.0,升級(jí)之快還是第一次吧,看來百度對(duì)于刷點(diǎn)擊行為是零容忍了。之前尹華峰SEO技術(shù)博客介紹過一篇如何使用刷點(diǎn)擊工具,其實(shí)市面上有很多這類SEO快速排名的軟件,…

        2022年11月25日
      • 抖音直播帶貨有哪些方法技巧(抖音直播帶貨有哪些痛點(diǎn))

        如今抖音這個(gè)短視頻的變現(xiàn)能力越來越突顯了,尤其是在平臺(tái)上開通直播,更具有超強(qiáng)的帶貨屬性,已經(jīng)有越來越多的普通人加入到其中了。不過直播帶貨雖然很火,但是也不是每個(gè)人都能做好的,那么在…

        2022年11月24日
      • 抖音世界杯投屏怎么弄 抖音看世界杯怎么看能投屏嗎

        抖音作為短視頻平臺(tái)第一次進(jìn)軍世界杯直播,小編還是很期待的,畢竟每天沒事的時(shí)候都會(huì)刷一下抖音,看直播的話也是方便了不少,那抖音看世界杯可以投屏嗎?下面一起來了解一下。 抖音世界杯投屏…

        2022年11月24日
      • 玩轉(zhuǎn)海外ASO優(yōu)化的8個(gè)技巧(蘋果aso優(yōu)化怎么做)

        在海外,一款A(yù)PP要呈現(xiàn)到用戶眼前,基本上都繞不開iOS和Android渠道商。那么,如何讓你的App被更多用戶發(fā)現(xiàn)呢?本文作者總結(jié)了8個(gè)APP海外ASO優(yōu)化推廣策略,一起來看一下…

        2022年11月24日

      聯(lián)系我們

      聯(lián)系郵箱:admin#wlmqw.com
      工作時(shí)間:周一至周五,10:30-18:30,節(jié)假日休息