在學習drop方法刪除用戶時,按照書上講的一直沒操作成功,後來到網上查了點其他資料,才弄明白drop的方法,貼出來和大家分享一下。
(方法一)drop user 用戶名;
語法:drop user 用戶名;
作用:刪除已經存在的用戶,例如要刪除yan這個用戶,(drop user yan;)默認刪除的是yan@"%"這個用戶,如果還有其他用戶,例如yan@"localhost",yan@"ip",則不會一起被刪除。如果只存在一個用戶yan@"localhost",使用語句(drop user yan;)會報錯,應該用(drop user yan@"localhost";)如果不能確定(用戶名@機器名)中的機器名,可以在mysql中的user表中進行查找,user列對應的是用戶名,host列對應的是機器名。
(方法二)delete from user where user="用戶名" and host="localhost";
delete也是刪除用戶的方法,例如要刪除yan@"localhost"用戶,則可以(delete from user where user="yan" and host="localhost";)
注:drop刪除掉的用戶不僅將user表中的數據刪除,還會刪除諸如db和其他權限表的內容。而(方法二)只是刪除了user表的內容,其他表不會被刪除,後期如果命名一個和已刪除用戶相同的名字,權限就會被繼承。