【问题标题】:Bash script - ERROR 1 (HY000) - save tables from databaseBash 脚本 - 错误 1 ​​(HY000) - 从数据库中保存表
【发布时间】:2014-09-07 17:08:41
【问题描述】:

我必须修复一些停止工作的脚本。 有export.sh 脚本,它应该从数据库中复制和保存表:

DATAPUMP="/tmp/DataPump/"       # Where tables have to be saved and where the old tables are saved 
TABLELIST="MyShop5TableList"    # Where names of tables are saved
DBSOURCE="somedb"               # DB name
EXPORTDIR="../export/"          # Where copies of tables have to be saved

rm ${DATAPUMP}*.export

for table in `cat ${TABLELIST}`; do
mysql -D ${DBSOURCE} -pPassword << EOF
select * into outfile "${DATAPUMP}${table}.export" from ${table};
EOF
done

cp ${DATAPUMP}* ${EXPORTDIR}

当我尝试运行脚本 export.sh 时,出现错误消息:

rm: cannot remove '/tmp/DataPump/*.export': No such file or directory.
ERROR 1 (HY000): Can’t create/write to file "/tmp/DataPump/goods.export"(Errcode: 2)
# *and the same ERROR 1 for all other tables*

所以我尝试将 DATAPUMP 目录更改为DATAPUMP="tmp/DataPump/"(只是没有开头的“/”)。文件已被删除,但仍然出现 ERROR 1 消息(现在有点不同):

ERROR 1 (HY000): Can’t create/write to file "var/lib/mysql/tmp/DataPump/goods.export"(Errcode: 2)
# *and the same ERROR 1 for all other tables*

文件的路径已更改。我是 bash 脚本的新手,我真的不知道出了什么问题。 PS:脚本运行了很长时间......我们不知道发生了什么

【问题讨论】:

  • 脚本应该有写入DATAPUMP目录的权限。因此,您应该查看 /etc/crontab (或执行它的任何位置)以查看它是否以 root 用户或其他用户身份执行。然后查看 /tmp 是否有 DataPump 目录并且权限是否仍然正确。然后撤消更改并按照 crontab 中的定义运行脚本。也许只是有人删除了 /tmp 中的 DataPump 目录。
  • 我手动执行脚本,没有crontab。并授予here 之类的权限

标签: mysql database bash shell debian


【解决方案1】:

我不是 100% 确定,但我敢打赌这是权限。尝试 chown 您正在写入文件的目录。然后运行脚本。

chown -R foo /some/path

这会将 /some/path 的路径目录的所有权从 root 更改为 foo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多