首页 > 代码库 > mysql 用户/密码/权限操作

mysql 用户/密码/权限操作

由于最近使用mysql遇到了修改用户密码的问题,所以一块学习了一下关于用户的相关操作;

1. 创建新账户

CREATE USER jeffrey@localhost;

 

  

2. 账户设置密码

#当前用户设置密码
SET PASSWORD = PASSWORD(mypass);

#给指定账户设置密码
SET PASSWORD FOR jeffrey@localhost = PASSWORD(mypass);

 

 

3. 给账户赋权限

#赋权限
GRANT ALL ON db1.* TO jeffrey@localhost;

#刷新权限
flush privileges;

  

  刷新权限的方式有多种,如上只是其中的一种方式。详情点击 或 如下:

 

技术分享

 

    可赋值的权限如下表:

 

Table 13.3 Permissible Privileges for GRANT and REVOKE

PrivilegeMeaning and Grantable Levels
ALL [PRIVILEGES] Grant all privileges at specified access level except GRANT OPTION and PROXY.
ALTER Enable use of ALTER TABLE. Levels: Global, database, table.
ALTER ROUTINE Enable stored routines to be altered or dropped. Levels: Global, database, procedure.
CREATE Enable database and table creation. Levels: Global, database, table.
CREATE ROUTINE Enable stored routine creation. Levels: Global, database.
CREATE TABLESPACE Enable tablespaces and log file groups to be created, altered, or dropped. Level: Global.
CREATE TEMPORARY TABLES Enable use of CREATE TEMPORARY TABLE. Levels: Global, database.
CREATE USER Enable use of CREATE USERDROP USERRENAME USER, and REVOKE ALL PRIVILEGES. Level: Global.
CREATE VIEW Enable views to be created or altered. Levels: Global, database, table.
DELETE Enable use of DELETE. Level: Global, database, table.
DROP Enable databases, tables, and views to be dropped. Levels: Global, database, table.
EVENT Enable use of events for the Event Scheduler. Levels: Global, database.
EXECUTE Enable the user to execute stored routines. Levels: Global, database, table.
FILE Enable the user to cause the server to read or write files. Level: Global.
GRANT OPTION Enable privileges to be granted to or removed from other accounts. Levels: Global, database, table, procedure, proxy.
INDEX Enable indexes to be created or dropped. Levels: Global, database, table.
INSERT Enable use of INSERT. Levels: Global, database, table, column.
LOCK TABLES Enable use of LOCK TABLES on tables for which you have the SELECT privilege. Levels: Global, database.
PROCESS Enable the user to see all processes with SHOW PROCESSLIST. Level: Global.
PROXY Enable user proxying. Level: From user to user.
REFERENCES Enable foreign key creation. Levels: Global, database, table, column.
RELOAD Enable use of FLUSH operations. Level: Global.
REPLICATION CLIENT Enable the user to ask where master or slave servers are. Level: Global.
REPLICATION SLAVE Enable replication slaves to read binary log events from the master. Level: Global.
SELECT Enable use of SELECT. Levels: Global, database, table, column.
SHOW DATABASES Enable SHOW DATABASES to show all databases. Level: Global.
SHOW VIEW Enable use of SHOW CREATE VIEW. Levels: Global, database, table.
SHUTDOWN Enable use of mysqladmin shutdown. Level: Global.
SUPER Enable use of other administrative operations such as CHANGE MASTER TOKILLPURGE BINARY LOGSSET GLOBAL, and mysqladmin debug command. Level: Global.
TRIGGER Enable trigger operations. Levels: Global, database, table.
UPDATE Enable use of UPDATE. Levels: Global, database, table, column.
USAGE Synonym for no privileges”

 

 4. 常用mysql命令

#查看当前用户
select current_user;
select current_user();

#格式化输出结果 字符/G 代表格式化输出
select * from t where t.id = 1/G;

 

 

5. 参考链接

  1.  https://dev.mysql.com/doc/refman/5.6/en/set-password.html

  2. https://dev.mysql.com/doc/refman/5.7/en/create-user.html#create-user-previous

  3. https://dev.mysql.com/doc/refman/5.6/en/grant.html

  4. https://dev.mysql.com/doc/refman/5.7/en/privilege-changes.html

  

mysql 用户/密码/权限操作