本文转载自微信公众号「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/bin2: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;
关于这个问题,还有可能是因为视图引用了无效的表,列或函数,而不一定是视图的定义者/调用器缺乏调用它们的权限。