Created
November 10, 2023 08:43
-
-
Save NoahBohme/c91294c9a6da369e5df08408c63ceb3b to your computer and use it in GitHub Desktop.
Get the database of mysql from local host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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