今天学习的主要内容是刘金玉老师MySQL数据库零基础教程第26期。学习的内容是mysql授权给指定用户权限。
一、登录账号并查看sql数据用户
在开始菜单栏输入cmd命令启动cmd编辑窗口,然后输入mysql -uroot-p命令行,使用之前设置的密码root即可登录mysql数据库。然后分别输入以下语句:
Use mysql;
Select host,user from user;
这里的host表示范围,user表示用户名。
二、创建用户并授权
(一)mysql权限表
ALTER | Allows use of ALTER TABLE. |
ALTER ROUTINE | Alters or drops stored routines. |
CREATE | Allows use of CREATE TABLE. |
CREATE ROUTINE | Creates stored routines. |
CREATE TEMPORARY TABLE | Allows use of CREATE TEMPORARY TABLE. |
CREATE USER | Allows use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES. |
CREATE VIEW | Allows use of CREATE VIEW. |
DELETE | Allows use of DELETE. |
DROP | Allows use of DROP TABLE. |
EXECUTE | Allows the user to run stored routines. |
FILE | Allows use of SELECT... INTO OUTFILE and LOAD DATA INFILE. |
INDEX | Allows use of CREATE INDEX and DROP INDEX. |
INSERT | Allows use of INSERT. |
LOCK TABLES | Allows use of LOCK TABLES on tables for which the user also has SELECT privileges. |
PROCESS | Allows use of SHOW FULL PROCESSLIST. |
RELOAD | Allows use of FLUSH. |
REPLICATION | Allows the user to ask where slave or master |
CLIENT | servers are. |
REPLICATION SLAVE | Needed for replication slaves. |
SELECT | Allows use of SELECT. |
SHOW DATABASES | Allows use of SHOW DATABASES. |
SHOW VIEW | Allows use of SHOW CREATE VIEW. |
SHUTDOWN | Allows use of mysqladmin shutdown. |
SUPER | Allows use of CHANGE MASTER, KILL, PURGE MASTER LOGS, and SET GLOBAL SQL statements. Allows mysqladmin debug command. Allows one extra connection to be made if maximum connections are reached. |
UPDATE | Allows use of UPDATE. |
USAGE | Allows connection without any specific privileges. |
(二)数据库管理员给用户授权
补充知识:在使用数据库时候,如果没有进入该数据库,也可以通过加上数据库的名称来直接查询数据库内表的内容,例如:查询mysql有哪些账号,使用语句select host,user from mysql.user;创建一个账号后,该账号默认包含有连接权限,即USAGE权限。
1.如何查看账号的权限
语法结构:show grants for 账号
案例:查看mysql账号mianyang的权限
语句:show grants for 'mianyang' @'localhost';
2.给指定用户授权
语法结构:grant 指定权限(中间有多个权限时候有逗号隔开) on 数据库 to 用户 identified by '密码' (一般来说,一个账号管理一个指定的数据库,有指定的有权限的数据库。)
第一种:对一个用户授予指定的一个数据库的某些权限
案例:授予mianyang用户有查询、更新数据库sichuan的权限
语句:grant select,update on sichuan.* to 'mianyang' @ 'localhost';
第二种:对一个用户授予所有数据库的的某些权限
下一期学习见。