AutoMySQLBackup遇到的幾個(gè)問題
本文轉(zhuǎn)載自微信公眾號「DBA閑思雜想錄」,作者瀟湘隱者。轉(zhuǎn)載本文請聯(lián)系DBA閑思雜想錄公眾號。
1:使用AutoMySQLBackup時(shí)遇到錯(cuò)誤:Error: Dependency programs are missing. Perhaps they are not in $PATH. Exiting
使用AutoMySQLBackup備份MariDB時(shí),手工執(zhí)行shell腳本中的腳本 /mysql_backup/scripts/automysqlbackup /mysql_backup/scripts/conf/myserver.conf 沒有問題。但是在作業(yè)(crontab)里面執(zhí)行腳本時(shí)遇到下面錯(cuò)誤:
- 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.
出現(xiàn)這個(gè)問題,一般是由于環(huán)境變量引起的。需要修改配置文件myserver.conf中的參數(shù)PATH,使用命令ps -ef | grep -i mysqld 找到mysqldump所在的路徑后,配置myserver.conf的參數(shù)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其實(shí)是封裝了mysqldump的一個(gè)shell腳本,在一個(gè)案例中,具體報(bào)錯(cuò)如下所示:
- ====================================================================================================================================
- .............................................................................................................................
- 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)
- .............................................................................................................................
- ====================================================================================================================================
遇到這個(gè)問題,首先檢查賬號權(quán)限,AutoMySQLBackup使用的賬號為dbbackup,具體權(quán)限如下所示,一般而言,這樣的權(quán)限是沒有問題的。
- 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,切換到對應(yīng)用戶數(shù)據(jù)庫,執(zhí)行下面命名時(shí),還真遇到了權(quán)限問題。
- 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;
最后一一排查下來,發(fā)現(xiàn)是視圖xxx中引用了一個(gè)Function,但是用戶dbbckup沒有這個(gè)函數(shù)的執(zhí)行權(quán)限,所以報(bào)這個(gè)錯(cuò)誤。授予用戶下面權(quán)限后,問題解決
- GRANT EXECUTE ON xxx.* TO 'dbbackup'@'127.0.0.1';
- FLUSH PRIVILEGES;
關(guān)于這個(gè)問題,還有可能是因?yàn)橐晥D引用了無效的表,列或函數(shù),而不一定是視圖的定義者/調(diào)用器缺乏調(diào)用它們的權(quán)限。