您好,登錄后才能下訂單哦!
命 令 | 含 義 |
---|---|
show databases; | 查看當(dāng)前數(shù)據(jù)庫所有的庫 |
show create database 數(shù)據(jù)庫名; | 查看當(dāng)前數(shù)據(jù)的創(chuàng)建方式 |
create database 數(shù)據(jù)庫名; | 使用系統(tǒng)默認(rèn)的字符集創(chuàng)建數(shù)據(jù)庫 |
create database 數(shù)據(jù)庫名 character set 字符集; | 使用制定的字符集創(chuàng)建數(shù)據(jù)庫 |
drop database 數(shù)據(jù)庫名; | 刪除指定名稱數(shù)據(jù)庫 |
-- 這是注釋 | 注釋語句 |
alter database 數(shù)據(jù)庫名稱 character set 字符集; | 修改指定名稱數(shù)據(jù)庫的字符集 |
use 數(shù)據(jù)庫名; | 使用指定名稱的數(shù)據(jù)庫 |
select database(); | 查看當(dāng)前正在使用的數(shù)據(jù)庫 |
create table 表名(列名 數(shù)據(jù)類型,... 列名(最后一個(gè)不需要逗號(hào))); | 創(chuàng)建表 |
show tables; | 查看當(dāng)前數(shù)據(jù)庫的所有的表 |
show create table 表名; | 查看指定數(shù)據(jù)庫中某個(gè)表的創(chuàng)建信息 |
desc 表名; | 查看表信息 |
alter table 表名 add 列名 列數(shù)據(jù)類型 約束 | 在比表中增加列 |
alter table 表名 modify 列名 修改內(nèi)容 約束 | 修改列的信息 |
alter table 表名 change 列名 修改后的名字 約束 | 修改列名字 |
alter table 表名 drop 列名 | 刪除指定列 |
rename table 表名(修改前) to 表名(修改后) | 修改表名 |
alter table 表名 character set 字符集 | 修改表的字符集 |
drop table 表名 | 刪除指定名字的表 |
---|---|
select * from 表名 | 查看表中的數(shù)據(jù) |
insert into user(列1, ... , 列5) values(值1, ... , 值5); | 所有列全部定義 |
insert into user(列1, 列3, 列5) values(值1, 值3, 值5); | 部分列選擇定義 |
insert into user values(值1, 值2, 值3, 值4, 值5); | 省略列名, 值需要全部提供 |
update 表名 set 列名 = 值 [where 條件]; [ ]表示可選 | 修改表記錄 |
delete from 表名 [where 條件];[ ]表示可選 | 刪除表中數(shù)據(jù),一行一行刪除,效率低 |
truncate table 表名 | 刪除整個(gè)表,并創(chuàng)建一個(gè)同名新表 |
select 列名,列名,… from 表名 | 查找表中指定列的信息 |
select * from 表名 where 條件判斷 | 條件查詢 |
> < <= >= = <> !=(不等于,不推薦使用,并不是sql語言) | 大于、小于、大于/小于等于、不等于 |
between a and b | 在指定的a和b之間(包含a和b) |
_ | 表示任意一個(gè)字符 |
% | 表示任意零個(gè)多個(gè)字符 |
is null、is not null | 是否為空,是否為非空 |
and && | 條件同時(shí)成立 |
or || | 條件任意成立一個(gè)即可 |
not | 條件不成立 |
select distinct 列名 from 表名 | 過濾掉某列中的重復(fù)數(shù)據(jù) |
a as b | 別名 |
order by asc / desc | 升序排列/降序排列 (默認(rèn)升序) |
---|---|
ifnull(列名, 默認(rèn)值) | 如果表中某個(gè)數(shù)據(jù)為null,在計(jì)算的時(shí)候可以賦默認(rèn)值 |
avg() | 聚合函數(shù),求平均值 |
count() | 聚合函數(shù),計(jì)數(shù) |
max() | 聚合函數(shù),最大值 |
min() | 聚合函數(shù),最小值 |
sum() | 聚合函數(shù),求和 |
group by 條件 | 分組查詢 |
group by 條件 ,having 條件 | 分組后實(shí)現(xiàn)過濾 |
mysqldump -u 用戶名 -p 數(shù)據(jù)庫名 > 磁盤SQL文件路徑 | 數(shù)據(jù)庫備份 |
mysql -u 用戶名 -p 導(dǎo)入庫名 < 硬盤SQL文件絕對(duì)路徑 | 數(shù)據(jù)庫恢復(fù)---推薦 |
source 硬盤SQL文件絕對(duì)路徑 | 數(shù)據(jù)庫恢復(fù) |
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。