MySQL創建用戶並授權
第一步 WIN + R cmd 進入DOS 命令窗口
輸入 mysql -uroot -p 回車然后輸入密碼
一、 創建用戶
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
username: 你將創建用戶的名字
localhost : 本地用戶,如果想讓該用戶可以從任意遠程主機登陸,可以使用%
identified by : 密碼為。。。。。
password : 密碼
例: create user'fuck'@'localhost' identified by '123'; create user'fuck'@'%' identified by '123'
二、 授權
GRANT all ON databasename.* TO 'username'@'localhost';
使得username 這個用戶 獲得能對 databasename 這個數據庫中的所有表進行操作
例:create database study charset utf8;
grant all on study.* to 'fuck'@'localhost';
grant all on study.student to 'fuck'@'localhost';
三、刪除用戶
DROP USER 'username'@'localhost';
四、撤銷權限
REVOKE all ON databasename.tablename FROM 'username'@'localhost';