MySQL遷移後提示查詢view權限不足的處理

一.問題描述:
開發人員反應xx物流系統mysql查詢視圖提示權限不足,請DBA介入處理.
MariaDB [abc]> select * from c_time;
ERROR 1045 (28000): Access denied for user 'lsa'@'%' (using password: YES)
版本:mariadb 10.1.18 for centos 6.6
二.問題分析:
查看lsa'@'%賬號權限以下:
MariaDB [(none)]> show grants for lsa @'%';
+--------------------------------------------------------------------------------------------------------+
| Grants for lsa@% |
+--------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'lsa'@'%' IDENTIFIED BY PASSWORD 'xxxxxxxx' |
| GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE, SHOW VIEW ON `abc`.* TO 'lsa'@'%' |
+--------------------------------------------------------------------------------------------------------+
以上說明已存在show view查詢視圖的權限,爲啥還報這個錯,是否爲開發人員操做不當引發,如是dba親自驗證用lsa賬號登入查詢視圖試試,確認問題存在,猜測難道是show view權限 
不生效引發,如是,從新刷新權限:
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
通過權限刷新操做後,問題仍是依然存在,以下:
MariaDB [abc]> select * from c_time;
ERROR 1045 (28000): Access denied for user 'lsa'@'%' (using password: YES)
用lsa賬號查詢其它表都正常,用mysql的root賬號登入查詢視圖,此時報錯又不同:
MariaDB [(none)]> use abc
Database changed
MariaDB [abc]> select count(*) from c_time;
ERROR 1449 (HY000): The user specified as a definer ('abcadmin'@'%') does not exist
不過以上報錯提示比較明顯,'abcadmin'@'%'賬號不存在這個視圖,如是咱們查看視圖的定義結構:
MariaDB [abc]> show create view c_time\G
*************************** 1. row ***************************
View: c_time
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`abcadmin`@`%` SQL SECURITY DEFINER VIEW `c_time` AS 
............
character_set_client: utf8
collation_connection: utf8_general_ci
1 row in set, 1 warning (0.00 sec)
上面可看出視圖的DEFINER爲`abcadmin`@`%` ,abcadmin賬號是用於給開發執行ddl操做的,因爲自助平臺徹底代替了手工執行ddl腳本,因此此次遷移到南海就沒有再創建abcadmin。
三.問題解決:
上面找到緣由後,解決就比較方便。
方法一:創建abcadmin賬號
創建abcadmin賬號後,能夠正常查詢:
 MariaDB [abc]> select count(*) from c_time;
+----------+
| count(*) |
+----------+
| 440069 |
+----------+
1 row in set (0.96 sec)
方法二:修改DEFINER
將DEFINER=`abcadmin`@`%`修改DEFINER=`lsa`@`%` 
alter ALGORITHM=UNDEFINED DEFINER=`lsa`@`%` SQL SECURITY DEFINER VIEW `c_time` AS 
............
修改definer後,也可正常查詢:
MariaDB [abc]> select count(*) from c_time;
+----------+
| count(*) |
+----------+
| 440069 |
+----------+
1 row in set (0.96 sec)
最後權衡分析,咱們採用方法二解決問題。
相關文章
相關標籤/搜索