From 0ce6d6eb0b4b4077ec9228122c669d53dc70397c Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 28 Aug 2024 23:45:59 +0800 Subject: [PATCH] Shell Script DB Prep --- scripts/dbPreparation.sh | 107 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 scripts/dbPreparation.sh diff --git a/scripts/dbPreparation.sh b/scripts/dbPreparation.sh new file mode 100644 index 0000000..0af733b --- /dev/null +++ b/scripts/dbPreparation.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# Automatically generate a new secure password for the root user +new_root_password=$(openssl rand -base64 12) + +# Generate random database name, user, and password for the new database +DB_NAME="db_$(openssl rand -hex 4)" +DB_USER="user_$(openssl rand -hex 4)" +DB_PASSWORD="$(openssl rand -base64 12)" +DB_HOST="localhost" # Change if your database is hosted elsewhere + +echo "New root password will be: $new_root_password" +echo "New database credentials:" +echo "Database Name: $DB_NAME" +echo "Database User: $DB_USER" +echo "Database Password: $DB_PASSWORD" + +echo "Attempting to stop the MariaDB service..." +# Stop the MariaDB service +sudo systemctl stop mariadb + +echo "Starting MariaDB in safe mode..." +# Start MariaDB in safe mode with no networking and no grants +sudo mysqld_safe --skip-grant-tables --skip-networking & + +# Wait for MariaDB to fully start in safe mode +sleep 5 + +echo "Resetting the root password..." +# Reset the root password in safe mode +sudo mysql -u root <