提问人:boyenec 提问时间:6/30/2023 最后编辑:Shadowboyenec 更新时间:6/30/2023 访问量:33
获取 mysql 转储 1045:尝试使用 sh 脚本备份 mysql 数据库时出现访问被拒绝错误
getting mysql dump 1045: Access denied error when trying to backup mysql database using sh script
问:
这是我的 .sh 脚本,它将每小时备份一次 MySQL 数据库,然后上传到我的 S3 存储桶
GNU nano 6.2 backup-script.sh
#!/bin/bash
# Define variables
DB_HOST="localhost"
DB_USER="myusername"
DB_PASSWORD="mydpassowrd"
DB_NAME="mydb name"
S3_BUCKET="my s3 bucjet name"
BACKUP_FILENAME="backup.sql.gz"
EMAIL_ADDRESS=""
LOG_FILE="/root/backup-log.txt"
# Perform MySQL backup
mysqldump -h $DB_HOST -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip > $BACKUP_FILENAME
...others code
我的备份已成功上传,但现在我仍然收到此错误:
Enter password: mysqldump: Got error: 1045: Access denied for user 'user'@'localhost' (using password: NO) when trying to connect
Completed 20 Bytes/20 Bytes (15 Bytes/s) with 1 file(s) remaining
我还为用户添加了授予所有权限。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' WITH GRANT OPTION;
答: 暂无答案
评论
DB_USER="myuser"
也许。还要看壳牌报价DB_USER="myusername"
!= 但我认为你隐藏了太多不一致的细节,很难确定问题所在。TO 'myuser'@'%'
(using password: NO)
因此,它似乎丢失了您的密码-h $DB_HOST -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip > $BACKUP_FILENAME