Combining DROP USER and DROP DATABASE with SELECT .. WHERE query?
Posted
by
zsero
on Stack Overflow
See other posts from Stack Overflow
or by zsero
Published on 2012-09-09T19:58:16Z
Indexed on
2012/09/09
21:38 UTC
Read the original article
Hit count: 251
I'd like to make a very simple thing, replicate the functionality of mysql's interactive mysql_secure_installation script. My question is that is there a simple, built-in way in MySQL to combine the output of a SELECT query with the input of a DROP user or DROP database script?
For example, if I'd like to drop all users with empty passwords. How could I do that with DROP USER statement? I know an obvious solution would be to run everything for example from a Python script,
- run a query with
mysql -Bse "select..."
- parse the output with some program
- construct the drop query
- run it.
Is there an easy way to do it in a simple SQL query? I've seen some example here, but I wouldn't call it simple: http://stackoverflow.com/a/12097567/518169
Would you recommend making a combined query, or just to parse the output using for example Python or bash scripts/sed?
© Stack Overflow or respective owner