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