#!/bin/bash # Bash script written by Saad Ismail - me@saadismail.net # edit to change _db.php # If /root/.my.cnf exists then it won't ask for root password if [ -f /root/.my.cnf ]; then echo "Please enter the NAME of the new MySQL database! (example: database1)" read dbname sudo sed -i "s/drm/$dbname/g" /var/www/html/_db.php echo "Please enter the MySQL database CHARACTER SET! (example: latin1, utf8, ...)" echo "Enter utf8 if you don't know what you are doing" read charset echo "Creating new MySQL database..." sudo mysql -e "CREATE DATABASE ${dbname} /*\!40100 DEFAULT CHARACTER SET ${charset} */;" echo "Database successfully created!" echo "Showing existing databases..." sudo mysql -e "show databases;" echo "" echo "Please enter the NAME of the new MySQL database user! (example: user1)" read username sudo sed -i "s/admin/$username/g" /var/www/html/_db.php echo "Please enter the PASSWORD for the new MySQL database user!" echo "Note: password will be hidden when typing" read -s userpass sudo sed -i "s/passwd/$userpass/g" /var/www/html/_db.php echo "Creating new user..." sudo mysql -e "CREATE USER ${username}@localhost IDENTIFIED BY '${userpass}';" echo "User successfully created!" echo "" echo "Granting ALL privileges on ${dbname} to ${username}!" sudo mysql -e "GRANT ALL PRIVILEGES ON ${dbname}.* TO '${username}'@'localhost';" sudo mysql -e "FLUSH PRIVILEGES;" sudo mysql ${dbname} < db.sql echo "Please enter root user MySQL password!" echo "Note: password will be hidden when typing" read -s rootpasswd # MySQL commands commands=$(cat <