SOLVED(sort of): OT: deleting tables from mysql using wildcard
Ron Johnson wrote:
> Kent West wrote:
> >> I have a lot of tables in a mysql database starting with "phpWeb"; I
> >> want to delete them. I can delete them one-by-one with a command like:
> >>
> >> drop table phpWebmod_modules;
> >>
> >> Rather than trying to delete all 20-30 similar tables, a wildcard
> >> command would be really nice hear. I've been googling for the last
> >> couple of hours, and haven't found the solution. Yes, I've tried *
> and %
> >> and putting the names in single-quotes, as in
> >>
> >> drop table phpWeb%
> >> drop table phpWeb*
> >> drop table 'phpWeb*'
> >> drop table 'phpWeb%'
>
> Are there compound statements in MySQL?
>
> for :x as each row of
> select table_name
> from syscatalog
> where sysrelation starting with 'phpWeb'
> do
> drop table :x.table_name cascade;
> end for;
I'm not a MySQL person; this is my first semi-significant foray into it.
So I'm unsure about the compound statements.
However, I solved my problem (with way more work than should have been)
by exporting the table list.
I created a text file, "bub.sh":
use joomla_church;
show tables;
quit
I then ran "mysql -p < bub.sh > bub.results". This created a text file
"bub.results" containing my list of tables. I then manually edited (with
some automation - search/replace) taking out the references to
non-phpWeb tables, etc; the resulting file looked something like:
use joomla_church;
drop table phpWebmod_modules;
drop table phpWeb_blah;
.
.
.
drop table phpWeb_lastitem;
I then fed that back into mysql with "mysql -p < bub.results". Because I
had a typo (missing semi-colon, etc) here and there, I wound up having
to run this command 5 or 6 times (correcting a bit everytime), but I
eventually cleaned out all my tables.
Not as much work as it could have been; way more than it should have
been. A simple "drop table phpWeb*" would have been SO much easier. Oh,
well, that's a mysql issue, not Debian. I appreciate not getting flamed
for asking an off-topic question here; I only do so 'cause you folks are
the best resource on the web generally.
Thanks!
--
Kent
Reply to: