mysql創建用戶、賦權限、以及刪除用戶

1.創建用戶

mysql> create user 'username'@'localhost/%/ip' identified by 'password';
Query OK, 0 rows affected (0.05 sec)
// 說明 localhost/%/ip ,可以指定ip(限定ip訪問),localhost(本服務器訪問)以及%(不限制ip訪問)

2.賦予權限

mysql> grant select/update/insert/delete/alter/drop/create(能是一個或多個權限) on *.* to 'username'@'localhost/ip/%';
Query OK, 0 rows affected (0.01 sec)

3.刪除用戶delete和drop兩種刪除

推薦使用drop以防ERROR 1396 (HY000): Operation CREATE USER failed for 'username'@'password'

方式一:
mysql> delete from user where user='username' and host='localhost';
Query OK, 1 row affected (0.02 sec)
mysql> flush privileges; // 記得刷新權限表,如果不刷新的話,直接創建相同用戶會報錯。
Query OK, 0 rows affected (0.01 sec)

方式二:
mysql> drop user 'username'@'localhost';
Query OK, 0 rows affected (0.00 sec)

錯誤:
mysql> delete from user where user='username' and host='localhost';
Query OK, 1 row affected (0.02 sec)
mysql> create user 'username'@'localhost' identified by 'password';
ERROR 1396 (HY000): Operation CREATE USER failed for 'username'@'password'
解決:
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> create user 'username'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

 

發佈了30 篇原創文章 · 獲贊 21 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章