標籤:oca 空間 default roo 修改 change ant 修改表 insert
引擎
查看MySQL預設引擎:
show variables like ‘%storage_engine%‘;
查看錶引擎:
show table status from 資料庫名;
修改表引擎
alter table 表名 engine=InnoDB;
建立時直接定義引擎
create table 表名() engine=InnoDB;
編碼
資料庫中查看字串編碼:
show variables like‘character%‘;
修改資料庫中表的編碼:
alter table 表名 convert to character set utf8;
查看資料庫中表的編碼(顯示完整的建表語句)
show create table 表名
建立資料庫時指定資料庫的字元集:
create database 資料庫名 character set utf8;
建立資料表時指定資料表的編碼格式:
create table tb_books (
name varchar(45) not null,
price double not null,
bookCount int not null,
author varchar(45) not null ) default charset = utf8;
修改欄位編碼格式:
alter table <表名> change <欄位名> <欄位名> <類型> character set utf8;
增刪改查
增加:
insert into 資料庫名 values(內容)
insert into 資料庫名(欄位) values(內容)
刪除:
delete from 表名 where 欄位
改寫:
update 表名 set 更改內容(name=1) where id=1
查 :
select * from 表名
修改表結構
alter table 表名 change 舊欄位名 新欄位名 欄位類型
索引
1.普通索引
2.唯一索引
3.全文索引
4.單列索引
5.多列索引
6.空間索引
7.主鍵索引
8.複合式索引
普通索引:僅加速查詢
唯一索引:加速查詢 + 列值唯一(可以有null)
主鍵索引:加速查詢 + 列值唯一 + 表中只有一個(不可以有null)
複合式索引:多列值組成一個索引,專門用於組合搜尋,其效率大於索引合并
全文索引:對文本的內容進行分詞,進行搜尋
建立表+索引:
create table 表名(
nid int not null auto_increment primary key,
name varchar(32) not null,
email varchar(64) not null,
extra text,
index 索引名 (欄位名)
)
建立索引
create index 索引名 on 表名(欄位名)
刪除索引:
drop 索引名 on 表名;
查看索引
show index from 表名
修改資料庫root密碼:
mysql> set password for 使用者名稱@localhost = password(‘新密碼‘);
mysqladmin -u使用者名稱 -p舊密碼 password 新密碼
許可權
建立使用者(授權)
grant 許可權 on 資料庫.表 to ‘使用者名稱‘@‘登入主機‘ [INDENTIFIED BY ‘使用者密碼’];
撤銷許可權
remove 許可權 on 資料庫.表 from ‘使用者名稱‘@‘登入主機;
查看許可權:
show grants;//自己
show grants for 使用者名稱稱@主機名稱;
MySQL資料庫總結