標籤:唯一索引 插入 date val 檔案名稱 log 表名 base TE
MySQL資料庫對大小寫不敏感,如id和ID,select和SELECT.。
1.資料庫
create database <資料庫名> 建立資料庫
use <資料庫名> 串連資料庫
註:use表示當前串連上了哪個資料庫,並不會影響對其他資料庫的訪問
如: use db_1;
select * from db_2.logs
drop database <資料庫名> 刪除資料庫,不會提箱
drop database if exists <資料庫名> 如果存在,刪除資料庫
show databases 查詢所有資料庫
select version() 查詢資料庫版本
select database() 查詢資料庫名稱
2.表
show tables 查詢所有表
create table <表名>( <欄位名1> <類型1>[,...<欄位名n> <類型n>] ) 建立資料庫
drop table <表名> 刪除表
drop table if exist <表名> 如果存在,刪除表
rename table <原表名> to <新表名>
delete from <表名> where <運算式> 刪除表中資料
insert into <表名> [(<欄位名1>[,..<欄位名n > ])] values ( 值1 )[, ( 值n )] 插入資料
update <表名> set 欄位=值, ... where <運算式> 更新表中資料
select <欄位1,欄位2, ...> from <表名> where <運算式> order by <欄位x, ...> limit m,n group by <欄位y, ...> having <運算式> 查詢
alert table <表名> add <欄位名> <類型>[... 其他] 給表增加欄位
alert table <表名> drop <欄位名> 刪除表中的欄位
alert table <表名> change <原欄位名> <新欄位名> <新的類型> 修改表中欄位
alert table <表名> add index <索引名> (<欄位名1[, 欄位名2 ...]>) 給表添加索引
alert table <表名> add unique <索引名> (<欄位名>) 給表添加唯一索引
alert table <表名> add primary key (<欄位名>) 給表中的主鍵添加索引
3.備份
mysqldump -u <使用者名稱> -p <資料庫名> > 匯出的檔案名稱 匯出資料庫,匯出檔案預設在mysql/bin目錄下
mysqldump -u <使用者名稱> -p <資料庫名> <表名> > 匯出的檔案名稱
MySQL常用命令總結