๐ฏHow to transfer database from one server to another of WordPress site with script.๐
STEP 1:
#!/bin/bash
#Database credentials
DB_NAME=''
DB_USER=''
DB_PASSWORD=''
DB_HOST='localhost'
#Backup file name with date
BACKUP_FILE="${DB_NAME}$(date +'%Y%m%d%H%M%S').sql"
#Perform the database dump
mysqldump --user=$DB_USER --password=$DB_PASSWORD --host=$DB_HOST $DB_NAME > $BACKUP_FILE
#Check if the command was successful
if [ $? -eq 0 ]; then
echo "Database backup successful: $BACKUP_FILE"
else
echo "Error creating database backup"
fi
STEP 2:
-gzip database_name.sql
STEP 3:
#To the Destination server
-scp database_name.sql.gz user@destination_server:/path/to/destination
STEP 4 :
#unzip
---gunzip database_name.sql.gz
STEP 5:
#Import
-mysql -u username -p new_database_name < /path/to/destination/database_name.sql
(NOte: Fix the permission after everything)
ย