Thanks to jbsnakes yugio script.... i'm starting to learn a bit about using bash to connect to mysql and edit/change the database.... here is a script i'm playing with now.... just to learn the basics.....
Here is what i have done so far......
Code:
#!/bin/bash
#
##########################
# USA Linux Users Group #
# http://www.usalug.org #
# http://bashscripts.org #
##########################
#######################################################
# mysqlbash.sh
#######################################################
#
#
# FILE: mysqlbash.sh
# VERSION: 1.0
# DATE: 12-06-2005
#
# AUTHOR: Crouse - Please visit bashscripts.org and usalug.org
#
#
########################################################
####### DATABASE FUNCTIONS #######
list_databases ()
{
echo "Listing Current Databases"
/usr/bin/mysql -e "show databases;"
read -p "Hit any key to continue. " temp
}
create_database ()
{
/usr/bin/mysql -e "show databases;"
read -p "Enter new database name" DATABASENAME
/usr/bin/mysql -e "create database $DATABASENAME"
echo "Database $DATABASENAME created"
read -p "Hit any key to continue. " temp
}
delete_database ()
{
/usr/bin/mysql -e "show databases;"
read -p "Enter the name of the database you wish to remove" DATABASENAME
/usr/bin/mysql -e "drop database $DATABASENAME"
echo "Database $DATABASENAME removed"
read -p "Hit any key to continue. " temp
}
####### TABLE FUNCTIONS #######
viewtables ()
{
/usr/bin/mysql -e "show databases;"; read -p "Which database would you like to use : " DATABASENAME;
/usr/bin/mysql -e "use $DATABASENAME; show tables";read -p "Hit any key to continue : " temp;
}
####### MENU FUNCTIONS #######
headerfile ()
{
clear;
echo "*****************************************************";
echo "* MYSQL BASH INTERFACE *";
echo "*****************************************************";
echo " ";
echo "";
}
databasemenu ()
{
menu=" 1)show databases 2)create database 3)delete database 0)main menu"
while true; do
headerfile;
echo -e "$menu"
echo "";
read -p "Please choose one of the options above : " option
case $option in
1) list_databases; ;;
2) create_database; ;;
3) delete_database; ;;
0) mainmenu; ;;
*) echo "Sorry, that isn't an option, try again. "; sleep 2; ;;
esac
done;
}
tablemenu ()
{
menu=" 1) Show databases 2) View tables 0) Main Menu"
while true; do
headerfile;
echo -e "$menu"
echo "";
read -p "Please choose one of the options above : " option
case $option in
1) list_databases; ;;
2) viewtables; ;;
0) mainmenu; ;;
*) echo "Sorry, that isn't an option, try again. "; sleep 2; ;;
esac
done;
}
mainmenu ()
{
menu=" 1)Database Menu 2)Table Menu 0)Exit"
while true; do
headerfile;
echo -e "$menu"
echo "";
read -p "Please choose one of the options above : " option
case $option in
1) databasemenu; ;;
2) tablemenu; ;;
0) exit; ;;
*) echo "Sorry, that isn't an option, try again. "; sleep 2; ;;
esac
done;
}
mainmenu
exit
Still ...... A LOT to learn and do, but this seems really interesting
