Skip to content

Instantly share code, notes, and snippets.

@we4tech
Created January 24, 2013 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save we4tech/4618029 to your computer and use it in GitHub Desktop.
Save we4tech/4618029 to your computer and use it in GitHub Desktop.
Simple bash script to quickly import an existing schema to a fixed database or get quick access to mysql console.
#!/bin/bash
echo "---------------------------------------"
echo " Welcome to Quick Schema Importer "
echo "---------------------------------------"
ROOT=$PWD
CONF=""
# Ensure configuration file exists
if [[ -f "$ROOT/bin/conf/db.conf" ]]
then
until [[ -n $option ]]
do
echo "Available options:"
echo "------------------"
echo "1: Import schema"
echo "2: Enter MySQL console"
echo "3: Exit"
echo "Choose your operation:"
read option
case $option in
1)
until [[ -n $file ]]
do
echo "Enter schema file location:"
read file
done
mysql `cat $ROOT/bin/conf/db.conf` < $file
echo "$file imported."
;;
2)
mysql `cat $ROOT/bin/conf/db.conf`
;;
3)
echo "Good bye! see ya!"
exit
esac
done
else
until [[ -n $db_user ]]
do
echo "Please enter db username:"
read db_user
done
echo "Please enter MySQL socket file:"
read mysql_socket
if [[ -z $mysql_socket ]]
then
echo "Please enter MySQL host: (localhost)"
read host
# Set default host
if [[ -z $host ]]
then
host="localhost"
fi
echo "Please enter MySQL port: (3306)"
read port
# Set default port 3306
if [[ -z $port ]]
then
port=3306
fi
CONF="-p$port -h$host"
echo "MySQL host: $host, port: $port"
else
CONF="-S$mysql_socket"
echo "MySQL socket: $mysql_socket"
fi
until [[ -n $db_name ]]
do
echo "Please enter database name:"
read db_name
done
echo "Database name: $db_name"
echo "Writing configuration in conf/db.conf..."
CONF="$CONF -p -u$db_user $db_name"
echo $CONF > "$ROOT/bin/conf/db.conf"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment