mysql授权
与mysql授权相关的命令有create user、grant、revoke。
CREATE USER user [IDENTIFIED BY [PASSWORD] 'password'] [, user [IDENTIFIED BY [PASSWORD] 'password']] ...
create user用于创建数据库帐户,并会赋予它usage权限。
GTANT priv_type [(column_list)] [, pri_type [(column_list)]] ...
ON priv_level TO user [IDENTIFIED BY [PASSWORD] 'password']
[WITH GRANT OPTION]
grant用于受权给用户。其中主要的一些权限(priv_type)列出来:
ALL
ALTER
CREATE
CREATE TEMPORARY TABLES
CREATE USER
CREATE VIEW
DELETE
DROP
FILE
INDEX
INSERT
LOCT TABLES
PROCESS
RELOAD
SHOW DATABASE
SHOW VIEW
UPDATE
USAGE
mysql的权限分为:global level, database level, table level, column level, routine level
其中global level主要有: CREATE USER, FILE, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHOW DATABASES, SHUTDOWN, SUPER,这些权限在mysql.user里记录。
database level主要有: CREATE, DROP, EVENT, GRANT OPTION, and LOCK TABLES,这些权限在mysql.db里记录。
table level: ALTER, CREATE VIEW, CREATE, DELETE, DROP, GRANT OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER, UPDATE,记录于mysql.tables_priv。
clomun level: INSERT, SELECT, UPDATE,记录于mysql.cloumns_priv。
routine level: ALTER ROUTINE, CREATE ROUTINE, EXECUTE, GRANT OPTION,记录于mysql.procs_priv。
设置global level权限,使用 grant create user on *.* to 'test'@'localhost';
设置database level:grant create on `database`.* to 'test'@'localhost';
设置table level: grant alter on `database`.`tablename` to 'test'@'localhost';
设置column level: grant insert (colname1, ...) on `databasename`.`tablename` to 'test'@'localhost';
设置routine level: GRANT CREATE ROUTINE ON mydb.* TO 'someuser'@'somehost'; GRANT EXECUTE ON PROCEDURE mydb.myproc TO 'someuser'@'somehost';
查看用户权限
show grants for 'root'@'localhost'