問題描述

當我執行以下指令時,想要將 mydatabase 這個資料庫備份出來時

mysqldump -u myaccount -p mydatabase > backup.sql 

出現了以下錯誤訊息

mysqldump: Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespaces

原因與處理方式

這是因為 myaccount 這個用戶缺少了 PROCESS 這個權限。

請以 root 權限登入 mysql,並執行

GRANT PROCESS ON *.* TO 'myaccount'@'localhost';

這樣就可以啦。

注意事項

PROCESS 是個靜態、全域的權限,不能指定給單一的資料庫

如果你想執行以下的指令,想要讓 myaccount 只能處理 mydatabase 這個資料庫,是不行滴

# 這樣執行,會有錯誤
GRANT PROCESS ON mydatabase.* TO 'myaccount'@'localhost';

# 錯誤訊息如下:
# ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES

出現錯誤訊息:You are not allowed to create a user with GRANT

這很可能是因為帳號與主機 (Host) 的組合出錯了,請以 root 權限登入 mysql,執行

select User, Host From mysql.user;

檢查一下 Host 欄位,是 localhost 還是 %,然後再試試。

通常改為以下 SQL 指令,也就是把 localhost 換成 % ,就可以正常運作了。

GRANT PROCESS ON mydatabase.* TO 'myaccount'@'%';

參考資料

https://dev.mysql.com/doc/refman/5.7/en/grant.html

https://stackoverflow.com/questions/47460670/cannot-grant-privileges-to-a-user-using-root-on-mysql

Last modified: 2025-03-18

Author

Comments

Write a Reply or Comment

Your email address will not be published.