索引是一種特殊的文件(InnoDB數(shù)據(jù)表上的索引是表空間的一個(gè)組成部分),它們包含著對(duì)數(shù)據(jù)表里所有記錄的引用指針。
更通俗的說(shuō),數(shù)據(jù)庫(kù)索引好比是字典前面的目錄,能加快數(shù)據(jù)庫(kù)的查詢(xún)速度
索引的使用
查看索引
showindexfrom表名;
創(chuàng)建索引
如果指定字段是字符串,需要指定長(zhǎng)度,建議長(zhǎng)度與定義字段時(shí)的長(zhǎng)度一致
字段類(lèi)型如果不是字符串,可以不填寫(xiě)長(zhǎng)度部分
createindex索引名稱(chēng)on表名(字段名稱(chēng)(長(zhǎng)度))
刪除索引:
dropindex索引名稱(chēng)on表名;
查看所有用戶(hù)
selecthost,user,authentication_stringfromuser;
授權(quán)的方式
grant權(quán)限列表on數(shù)據(jù)庫(kù)to'用戶(hù)名'@'訪問(wèn)主機(jī)'identifiedby'密碼';
例子:
use mysql
-- 創(chuàng)建賬戶(hù) 授權(quán)
grant 權(quán)限列表on 數(shù)據(jù)庫(kù)to '用戶(hù)名'@'訪問(wèn)主機(jī)' identified by '密碼';
grant select on wn.* to 'laobeng'@'localhost' identified by '123456';
grant all privileges on wn.* to "laoli"@"%"identified by "12345678";
grant 權(quán)限名稱(chēng) on 數(shù)據(jù)庫(kù) to 賬戶(hù)@主機(jī) with grant option;
-- 刷新權(quán)限
flush privileges;
-- 刪除賬戶(hù)
drop user 'laobeng'@'localhost';-- 推薦
delete from user where user='laobeng'
-- 操作結(jié)束之后需要刷新權(quán)限
flushprivileges