'Mysqldump script strange issue
I have this script for taking backup a single database in Ubuntu server:
#! /bin/bash
TIMESTAMP=$(date +"%F-%H-%M-%S")
DIR=$(date +"%F")
BACKUP_DIR="/media/storagebox/database/"
MYSQL_USER="backup_user"
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD=mypass
MYSQLDUMP=/usr/bin/mysqldump
#HOST="localhost"
cd /media/storagebox/database/
find . -type d -mtime +13 -exec rm -rf {} \;
mkdir -p $DIR
cd $DIR
$MYSQLDUMP --no-tablespaces --lock-tables --databases magento234 -u$MYSQL_USER -p{$MYSQL_PASSWORD} > magento2-$TIMESTAMP.sql ;
#cd $BACKUP_DIR
rm -f *.gz
gzip *.sql
My issue is with mysqldump
Although if I run it from command line it works with bash script I get:
mysqldump: Got error: 1045: "Access denied for user 'backup_user'@'localhost' (using password: YES)" when trying to connect
I spent hours but I can't identify what is going on. For mysql I use mariadb 10.4.24 and authentication for all users are set with native mysql authentication. My passwords are fine and even if I put in the script root user I get same error.
Bash debug output:
++ date +%F-%H-%M-%S
+ TIMESTAMP=2022-04-27-21-44-38
++ date +%F
+ DIR=2022-04-27
+ BACKUP_DIR=/media/storagebox/database/
+ MYSQL_USER=backup_user
+ MYSQL=/usr/bin/mysql
+ MYSQL_PASSWORD='mypass'
+ MYSQLDUMP=/usr/bin/mysqldump
+ cd /media/storagebox/database/
+ find . -type d -mtime +13 -exec rm -rf '{}' ';'
+ mkdir -p 2022-04-27
+ cd 2022-04-27
+ /usr/bin/mysqldump --no-tablespaces --lock-tables --databases magento234 -ubackup_user '-p{mypass}'
mysqldump: Got error: 1045: "Access denied for user 'backup_user'@'localhost' (using password: YES)" when trying to connect
+ rm -f magento2-2022-04-27-21-33-08.sql.gz
+ gzip magento2-2022-04-27-21-44-38.sql
Any help please?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
