PhyrePanel/shell/helpers/ubuntu/create-mysql-db-and-user.sh

26 lines
493 B
Bash
Raw Normal View History

2023-11-23 22:30:13 +00:00
#!/bin/bash
function create_mysql_db_and_user() {
echo "Creating MySQL user and database"
PASS=$3
if [ -z "$3" ]; then
PASS=`openssl rand -base64 8`
fi
mysql -u root <<MYSQL_SCRIPT
2023-11-23 22:34:53 +00:00
CREATE DATABASE $1;
CREATE USER '$2'@'localhost' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON $1.* TO '$2'@'localhost';
2023-11-23 22:30:13 +00:00
FLUSH PRIVILEGES;
MYSQL_SCRIPT
echo "MySQL user and database created."
echo "Database: $1"
2023-11-23 22:34:53 +00:00
echo "Username: $2"
2023-11-23 22:30:13 +00:00
echo "Password: $PASS"
2023-11-23 22:30:43 +00:00
echo "Success!"
2023-11-23 22:30:13 +00:00
}