在處理這個問題(https://www.cnblogs.com/abclife/p/11038660.html)的時候,開發同學在最后修改視圖的definer的時候又遇到了以下的報錯信息:
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'
數據庫版本是:mysql 5.7.25。讓他執行以下操作:
>select user(); >select current_user() from dual; >select host,user from mysql.user where user='root'; >show grants for root@'localhost'; >show grants for root@'%';
>select * from mysql.user where user='root';
反饋說用戶和權限都沒啥問題,然后再次讓其把執行報錯的現象截圖發過來:
root@localhost:information_schema 11:16:24>alter definer=`root`@`%` view <view_name> as select ... ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'
可以看到,它是在information_schema數據庫下執行,切換到視圖真正所在的數據庫再次執行命令就可以正確執行了。
因為information_schema是一個虛擬的數據庫,里面的表其實都是視圖。其實在導入數據的時候,也沒有必要將information_schema導一遍 。