I need a script that purges the tables in a database

Posted on 2004-11-22
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
Question by:mmartha
    LVL 5

    Accepted Solution

    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.
    LVL 4

    Expert Comment

    TRUNCATE TABLE is usually faster than delete...

    #! /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
    LVL 2

    Author Comment

    thanksss :)

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    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…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now