1. 程式人生 > >MySQL數據庫用戶、角色、授權

MySQL數據庫用戶、角色、授權

form roo inf error style clas -- logs fec

登錄MySQL

> mysql -h192.168.56.1 -P33060 -uroot -p
Enter password: ****

1. 添加用戶

insert into mysql.user(host,user,password) values(%, xiaoming, password(xiaoming123));

現在可以使用帳號(xiaoming,xiaoming123)登錄MySQL了。但是只有默認權限,僅能操作兩個數據庫,information_schema和test

2. 授權

grant <權限列表> on <關系> to <用戶/角色>

grant insert on school.* to xiaoming

此時,用戶xiaoming就擁有了對數據庫school的insert權限。

mysql> show databases; ---授權前
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.00 sec)

mysql> show databases; --- 授權後
+--------------------+ | Database | +--------------------+ | information_schema | | school | | test | +--------------------+ 3 rows in set (0.00 sec) mysql> use school; Database changed mysql> insert into student(name,score) values(xiaoming,60); Query OK,
1 row affected (0.08 sec) mysql> select * from student; ERROR 1142 (42000): SELECT command denied to user xiaoming@10.0.2.2 for table student

3. 添加用戶和授權

grant <權限> on <關系> to ‘<用戶>[email protected]<主機>‘ identified by ‘<密碼>‘

mysql> grant select on school.* to xiaoqiang@% identified by xiaoqiang123;

添加一個新用戶並授權

4. 創建角色

MySQL數據庫用戶、角色、授權