天天看點

大資料教程之算法系列資料庫使用者管理

  好程式員大資料教育訓練分享算法系列資料庫使用者管理1、使用者定義

  使用者定義:

  mysql> select user,host,password from mysql.user;

  +------+--------------+-------------------------------------------+

  | user | host | password

  ==================================

user 主機範圍

使用某個使用者 從哪些主機位址可以通路我的資料庫

使用者的功能:

1、用來登入mysql資料庫

2、用來管理資料庫對象(庫,表)

權限:

功能:針對不同的使用者,設定不同的對象管理能力。
select updata delete insert creat ...           

權限的範圍:

. :全局範圍

oldboy.* :單庫級别

oldboy.t1 :單表級别

建立使用者并授權:

grant all on wordpress.* to workpress@'10.0.0.%' identified by 'oldboy123';

授權指令 權限 權限範圍 用于 主機範圍 密碼

修改超級管理者使用者:root

修改密碼:mysqladmin -uroot -p password oldboy123

root@localhost

普通使用者:select,updata,delete,insert,create,drop (增删改查)

隻針對使用者的操作指令:

mysql> create user zabbix@'10.0.0.%' identified by 'oldboy123';

Query OK, 0 rows affected (0.01 sec)

mysql> drop user root@'127.0.0.1';

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from mysql.user;

特殊的删除方法:

mysql> delete from mysql.user where user='oldboy' and host='localhost';

Query OK, 1 row affected (0.00 sec)

mysql> flush privileges;

2、使用者授權

授權指令 權限 權限範圍 用于 主機範圍

all權限:

SELECT,INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES,

INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE,

REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE,

CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE

開發使用者權限:(root使用者進行授權)

grant SELECT,INSERT, UPDATE, DELETE, CREATE, DROP on testdb.* to zabbix@'10.0.0.%';           

使用zabbix檢查:

mysql> create database testdb;

mysql> show databases;

mysql> grant all on . to root@'10.0.0.%' identified by 'oldboy123';

查詢使用者的權限:

mysql> show grants for zabbix@'10.0.0.%';

建立類似管理者:

mysql> show grants for root@'10.0.0.%';

本地超級管理者:有grants權限

mysql> show grants for root@'localhost';

收回權限:

mysql> revoke create,drop on testdb.* from zabbix@'10.0.0.%';

思考:

grant select on . to zabbix@'10.0.0.%';

grant INSERT, UPDATE, DELETE, CREATE, DROP on testdb.* to zabbix@'10.0.0.%';

grant update on testdb.t1 to zabbix@'10.0.0.%';

mysql> use testdb;

mysql> create table t1(id int);

mysql> show tables;

mysql> insert into t1 values(1);

問:zabbix@'10.0.0.%' 對t1 表到底有什麼權限?

如果對某個使用者在不同的資料庫級别設定了權限,最終權限權限疊加,加起來的最大權限為準。

建議,不要多範圍授權。