Skip to content

Instantly share code, notes, and snippets.

@NoahBohme
Created November 10, 2023 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoahBohme/c91294c9a6da369e5df08408c63ceb3b to your computer and use it in GitHub Desktop.
Save NoahBohme/c91294c9a6da369e5df08408c63ceb3b to your computer and use it in GitHub Desktop.
Get the database of mysql from local host
#!/bin/bash
# Define the path to your WordPress wp-config.php file
wp_config="./wp-config.php"
# Extract database credentials from wp-config.php
db_name=$(grep -oP "DB_NAME\s*=\s*'(\K[^']+)" "$wp_config")
db_user=$(grep -oP "DB_USER\s*=\s*'(\K[^']+)" "$wp_config")
db_password=$(grep -oP "DB_PASSWORD\s*=\s*'(\K[^']+)" "$wp_config")
db_host=$(grep -oP "DB_HOST\s*=\s*'(\K[^']+)" "$wp_config")
# Set the path for the SQL dump file
dump_file="./wordpress-dump.sql"
# Create a SQL dump using mysqldump
mysqldump -u"$db_user" -p"$db_password" -h "$db_host" "$db_name" > "$dump_file"
# Check if mysqldump was successful
if [ $? -eq 0 ]; then
echo "WordPress database dumped to $dump_file"
else
echo "Error: Failed to dump WordPress database"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment