AutoMySQLBackup遇到的幾個問題
本文轉載自微信公眾號「DBA閑思雜想錄」,作者瀟湘隱者。轉載本文請聯系DBA閑思雜想錄公眾號。
1:使用AutoMySQLBackup時遇到錯誤:Error: Dependency programs are missing. Perhaps they are not in $PATH. Exiting
使用AutoMySQLBackup備份MariDB時,手工執行shell腳本中的腳本 /mysql_backup/scripts/automysqlbackup /mysql_backup/scripts/conf/myserver.conf 沒有問題。但是在作業(crontab)里面執行腳本時遇到下面錯誤:
- Note: Parsed config file /mysql_backup/scripts/conf/myserver.conf.
- Note: /etc/automysqlbackup/automysqlbackup.conf was not found - no global config file.
- Error: Dependency programs are missing. Perhaps they are not in $PATH. Exiting.
出現這個問題,一般是由于環境變量引起的。需要修改配置文件myserver.conf中的參數PATH,使用命令ps -ef | grep -i mysqld 找到mysqldump所在的路徑后,配置myserver.conf的參數PATH即可解決問題。
案例如下所示:
- #
- # Default values are stored in the script itself. Declarations in
- # /etc/automysqlbackup/automysqlbackup.conf will overwrite them. The
- # declarations in here will supersede all other.
- # Edit $PATH if mysql and mysqldump are not located in /usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin
- #PATH=${PATH}:FULL_PATH_TO_YOUR_DIR_CONTAINING_MYSQL:FULL_PATH_TO_YOUR_DIR_CONTAINING_MYSQLDUMP
- PATH=${PATH}:/app/mariadb/bin
2:mysqldump: Couldn't execute 'SHOW FIELDS FROM xxx': View xxxx.xxxx' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (1356)
AutoMySQLBackup其實是封裝了mysqldump的一個shell腳本,在一個案例中,具體報錯如下所示:
- ====================================================================================================================================
- .............................................................................................................................
- Errors reported during AutoMySQLBackup execution.. Backup failed
- Error log below..
- mysqldump: Couldn't execute 'SHOW FIELDS FROM `xxx`': View xxxx.xxxx' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (1356)
- .............................................................................................................................
- ====================================================================================================================================
遇到這個問題,首先檢查賬號權限,AutoMySQLBackup使用的賬號為dbbackup,具體權限如下所示,一般而言,這樣的權限是沒有問題的。
- GRANT SELECT, RELOAD, LOCK TABLES, REPLICATION CLIENT, SHOW VIEW, EVENT, TRIGGER ON *.* TO 'dbbackup'@'127.0.0.1';
- GRANT EXECUTE ON sys.* TO 'dbbackup'@'127.0.0.1';
- FLUSH PRIVILEGES;
使用dbbackup登錄MySQL,切換到對應用戶數據庫,執行下面命名時,還真遇到了權限問題。
- mysql> SHOW FIELDS FROM `xxx`;
- ERROR 1356 (HY000): View 'xxx.xxx' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
- mysql>
然后使用root賬號查看視圖定義
- mysql> show create view xxx\G;
最后一一排查下來,發現是視圖xxx中引用了一個Function,但是用戶dbbckup沒有這個函數的執行權限,所以報這個錯誤。授予用戶下面權限后,問題解決
- GRANT EXECUTE ON xxx.* TO 'dbbackup'@'127.0.0.1';
- FLUSH PRIVILEGES;
關于這個問題,還有可能是因為視圖引用了無效的表,列或函數,而不一定是視圖的定義者/調用器缺乏調用它們的權限。