?
Solved

I need a script that purges the tables in a database

Posted on 2004-11-22
3
Medium Priority
?
319 Views
Last Modified: 2010-04-20
i have the database db1 that have the tables tb1 tb2 and tb3.

I want to remove the information in that tables.

something like:

Select db1;
Select tb1;
delete *;
Select tb2;

etc... and into a bash script
0
Comment
Question by:mmartha
3 Comments
 
LVL 5

Accepted Solution

by:
ddunlea earned 2000 total points
ID: 12646434
Hi mmartha,

Assuming you're using mysql (a pretty big assumption), put the following into a text file, say "delete.sql"

use db1;
delete from tb1;
delete from tb2;

And then in you shell script, put the following:

mysql < delete.sql

You may also have to add user name and passwords on the command line if they apply to your setup.
0
 
LVL 4

Expert Comment

by:bytta
ID: 12646999
TRUNCATE TABLE is usually faster than delete...
http://dev.mysql.com/doc/mysql/en/TRUNCATE.html

#! /bin/bash
echo "use db1; truncate table tb1; truncate table tb2;truncate table tb3;" | mysql

mysql options:
-h HOST
-u USER
-pPASS (no space)
-p followed by a space will prompt for the mysql password
0
 
LVL 2

Author Comment

by:mmartha
ID: 12650653
thanksss :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month16 days, 20 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question