您的位置:首页 > 数据库

SQL 中用户建立与权限授予

2017-07-20 20:51 120 查看

SQL 中用户建立与权限授予

一、原有

如果大家对我的博客动态非常关注的话,应该又看到我弄了一个随机MAN信息的小工具。但是呢,那个工具还有待加强(显示效果不是那么的好)。

所以我就希望可以显示一些简短的,一目了然的。所以就有了现在的新项目https://github.com/erlinux/GetNewOne

二、效果



三、源码

#!/bin/usr/env python3
# -*- coding:utf-8 -*-
# @function:random dictum
# @author:jiwenkangatech@foxmail.com
# @license:MIT License
import random
import os

maths=random.randrange(1,150,1)
os.system('mysql -h itxdm.me -u article -p"article" -e "select article from article.article where id=%s" | sed -n "2p"' % (maths) )
exit(0)

所以会用到数据库,所以针对数据库用户创建与授权。

四、创建SQL用户

1、基础版

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

create是四大操作之一:CREATE DROP UPDATE SELECT

2、删除用户

DROP USER ‘demo’@‘localhost’;

3、登陆系统

mysql -u[username] -p[password]

注意:参数
-p
后加入双引号密码不加空格可跳过交互环境
(尾部加入
-e
参数可直接执行SQL语句)

FLUSH PRIVILEGES;
刷新权限表

五、用户权限赋予

0、预备知识

ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)

CREATE- allows them to create new tables or databases

DROP- allows them to them to delete tables or databases

DELETE- allows them to delete rows from tables

INSERT- allows them to insert rows into tables

SELECT- allows them to use the Select command to read through databases

UPDATE- allow them to update table rows

GRANT OPTION- allows them to grant or remove other users' privileges

1、基础版

GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;

tips:如果很难记住,可以尝试先记住查询的命令。(别给 [database name].[table name] 加双引号)

2、权限查询

SHOW GRANTS FOR ‘[username]’@'localhost’;

3、删除权限

REVOKE [type of permission] ON [database name].[table name] FROM ‘[username]’@‘localhost’;

FLUSH PRIVILEGES;
必要时,刷新权限

关于四大操作可参考以下图片文件(可保存)









差不多就是这些了。在我项目中有用到,在此记录。

本人并非DBA,理想的职业是运维开发。上述内容指点批评~

六:回顾:

作者通过自身项目需求,分享了位于 Linux 下 SQL 用户的创建与授权。进而分享了一系列资料:DCL、DDL、DML 与 手记一份。

七、参考:

1、以往参赛知识经验积累

2、美国云基础架构提供商

3、官方英文文档
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: