Register
It is currently Sun Aug 31, 2014 2:24 am

mysql and bash


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Thu Dec 08, 2005 11:52 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 666
Location: Des Moines, Iowa
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 ;)


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP