Skip to content

Instantly share code, notes, and snippets.

@masudur-rahman-niloy
Last active August 10, 2024 07:56
Show Gist options
  • Save masudur-rahman-niloy/2644c6739c5ba239287b4daa2d815f4f to your computer and use it in GitHub Desktop.
Save masudur-rahman-niloy/2644c6739c5ba239287b4daa2d815f4f to your computer and use it in GitHub Desktop.
bash script to backup mysql database
#!/bin/bash
# Database credentials
DB_USER="your_username" # change this
DB_PASSWORD="your_password" # change this
DB_NAME="your_database_name" # change this
# Backup directory
BACKUP_DIR="/path/to/backup/directory" # change this
# Timestamp (to create unique backup filenames)
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
# Create backup directory if it doesn't exist
mkdir -p $BACKUP_DIR
# Backup the MySQL database
mysqldump -u$DB_USER -p$DB_PASSWORD $DB_NAME > $BACKUP_DIR/$DB_NAME-$TIMESTAMP.sql
echo "Backup completed: $BACKUP_DIR/$DB_NAME-$TIMESTAMP.sql"
@masudur-rahman-niloy
Copy link
Author

installing mysql client is necessary. see this link for installing mysql-client

https://www.bytebase.com/blog/how-to-install-mysql-client-on-mac-ubuntu-centos-windows/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment