索引是一種特殊的文件(InnoDB數(shù)據(jù)表上的索引是表空間的一個組成部分),它們包含著對數(shù)據(jù)表里所有記錄的引用指針。
更通俗的說,數(shù)據(jù)庫索引好比是字典前面的目錄,能加快數(shù)據(jù)庫的查詢速度
索引的使用
查看索引
showindexfrom表名;
創(chuàng)建索引
如果指定字段是字符串,需要指定長度,建議長度與定義字段時的長度一致
字段類型如果不是字符串,可以不填寫長度部分
createindex索引名稱on表名(字段名稱(長度))
刪除索引:
dropindex索引名稱on表名;
查看所有用戶
selecthost,user,authentication_stringfromuser;
授權(quán)的方式
grant權(quán)限列表on數(shù)據(jù)庫to'用戶名'@'訪問主機'identifiedby'密碼';
例子:
use mysql
-- 創(chuàng)建賬戶 授權(quán)
grant 權(quán)限列表on 數(shù)據(jù)庫to '用戶名'@'訪問主機' 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)限名稱 on 數(shù)據(jù)庫 to 賬戶@主機 with grant option;
-- 刷新權(quán)限
flush privileges;
-- 刪除賬戶
drop user 'laobeng'@'localhost';-- 推薦
delete from user where user='laobeng'
-- 操作結(jié)束之后需要刷新權(quán)限
flushprivileges