很奇怪今天MySQL8突然出現(xiàn)一些莫明的錯誤,比如我昨天在用的帳戶,今天操作時報如下錯誤:
1227 - Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
具有root權(quán)限的用戶也報SYSTEM_USER權(quán)限不足,如何解決?看下面
MySQL8 Access denied解決
MySQL8版本中新增了一個system_user帳戶類型,當(dāng)我們新增一個用戶test,并用root用戶對test進(jìn)行密碼修改的操作時,系統(tǒng)不會報錯。
create user 'test'@'localhost' identified by 'test';
set password for 'test'@'localhost' = 'test1';
因為此時用戶test還沒有被授權(quán)。當(dāng)用戶test被授權(quán)后,再使用root對test修改密碼:
grant all on *.* to 'test'@'localhost';
set password for 'test'@'localhost' = 'test1';
這個時候系統(tǒng)會報錯:
1> 1227 - Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
我查閱了一下官方文檔,原因是由于root用戶沒有SYSTEM_USER權(quán)限,把權(quán)限加入后即可解決:
grant system_user on *.* to 'root';
然后再修改test密碼即可。不因為SYSTEM_USER權(quán)限涉及到所有帳戶操作,所以不僅是修改密碼,修改帳戶信息,授權(quán)等都會報這個錯,解決方法同樣是上面的操作。
參考
https://mysqlserverteam.com/the-system_user-dynamic-privilege/