我正在编写一个 .sh 文件,我试图访问一个 .sql 文件,其中有需要按计划运行的查询。
下面是我尝试连接到数据库的行:
/home/mysql/mysql/bin/mysql --port=$PORT --host=$HOST --user=$DB_USER --password=$DB_PASSWORD --database=$DB_NAME < ${SQL_SCRIPT_PATH}${SQL_SCRIPT_NAME} >> ${LOG_FILE_PATH}${LOG_FILE_NAME}
但是,问题是当调度程序执行时,它给出以下错误:
[example@mchpXXX TEST_sh]$ sh updateMonthlyUserData.sh
updateMonthlyUserData.sh: line 15: mysql: command not found
注意: 我尝试运行此命令,如果我从 putty 手动运行 sh 文件而不是通过 scheduler(crontab)
请检查并提供帮助。
最佳答案
Crontab 使用默认 shell (sh) 和最少的环境变量集。最有可能的是 PATH 变量设置不正确。
我会在脚本开头设置所有环境变量
#!/bin/bash
PATH=$PATH:/home/mysql/mysql/bin/:moreFolders
进一步阅读: How to get CRON to call in the correct PATHs https://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work
关于java - mysql 主机服务器未连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39465782/