1、進入資料庫,查看資料庫賬戶
# 進入資料庫 mysql –u root –p ---> 輸入密碼... # 使用 mysql 庫 use mysql; # 展示 mysql 庫中所有表 show tables; # 查看資料庫中 用戶地址 和 用戶 select host,user from user;
2、新增用戶
insert into user (Host,User,Password)values('localhost','zhengying',password('123456')); # 查詢驗證用戶新增成功 select host,user from user;
3、對用戶賦權
- 當 權限1,權限2,權限3,權限n 被 all privileges 或者 all 代替,表示賦予用戶全部權限
- 當 資料庫名稱.表名稱 被 *.* 代替,表示賦予用戶操作服務器上所有資料庫所有表的權限
- 用戶地址可以是 localhost,也可以是 IP 地址,機器名字,域名,還可以用 "%" 表示從任何地址連接
- 連介面令 不能為空,否則創建失敗
mysql> grant 權限1,權限2,…權限n on 資料庫名稱.表名稱 to "用戶名"@"用戶地址" identified by "連介面令";
# 給用戶賦所有權限 mysql> grant all privileges on *.* to "zhengying"@"%" identified by "123456"; # 重繪權限 mysql> flush privileges;
mysql> grant select,insert,update,delete,create,drop on user.t_user to "zhengying"@"localhost" identified by "123456"; # 給本機用戶 zhengying 分配可對資料庫 user 的 t_user 表進行select,insert,update,delete,create,drop 等操作的權限,并設定口令為 123456 # 重繪權限 mysql> flush privileges;
mysql> grant all privileges on user.* to "zhengying"@"localhost" identified by "123456"; # 給本機用戶 zhengying 分配可對資料庫 user 所有表進行所有操作的權限,并設定口令為 123456 # 重繪權限 mysql> flush privileges;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/58176.html
標籤:MySQL
上一篇:MySQL密碼加密與解密
下一篇:MySQL 庫操作
