Skip to content
Snippets Groups Projects
dbAndUserSetup.sh 1.16 KiB
Newer Older
srosse's avatar
srosse committed
#!/bin/bash
#################################################################################
# Initial database setup script: will generate db user and an openolat database #
# 11. July 2004 Florian Gnaegi                                                  #
#################################################################################
echo "This script will create a database user and a database for OpenOLAT on your MySQL server. Do you want to continue? (y|n)"
srosse's avatar
srosse committed
read Y
if [ "$Y" != "y" ]; then
	echo byby
	exit	
fi

# collect user dbname, username, password
srosse's avatar
srosse committed
read OLATDB
srosse's avatar
srosse committed
read OLATUSER
echo Enter the password for database user $OLATUSER:
read OLATPWD

# create mysql db query
QUERY="CREATE DATABASE $OLATDB; GRANT ALL PRIVILEGES ON $OLATDB.* TO '$OLATUSER'@'localhost' IDENTIFIED BY '$OLATPWD';"

# executing query
echo Generating now the OpenOLAT database user $OLATUSER with the password $OLATDB that has access to the database $OLATDB 
srosse's avatar
srosse committed
echo You must now enter the MySQL root user password:
mysql -u root -p mysql -e "$QUERY"
echo "User generated. Try login now with 'mysql -u $OLATUSER -p $OLATDB'"