snipt

Ctrl+h for KB shortcuts

Text only

Drop multiple tables wildcard

1
2
3
mysql -u root -D db_name -e "show tables" -s | 
  egrep "^wp_2_" | 
  xargs -I "@@" echo mysql -u root -D db_name -e "DROP TABLE @@"
https://snipt.net/embed/e5a728f8eb841e563749391bd636044e/
/raw/e5a728f8eb841e563749391bd636044e/
e5a728f8eb841e563749391bd636044e
text
Text only
3
2024-05-19T23:35:45
True
False
False
Jun 24, 2019 at 02:30 PM
/api/public/snipt/72/
drop-multiple-tables-wildcard
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>mysql -u root -D db_name -e &quot;show tables&quot; -s | </span><span id="L-2"><a name="L-2"></a> egrep &quot;^wp_2_&quot; | </span><span id="L-3"><a name="L-3"></a> xargs -I &quot;@@&quot; echo mysql -u root -D db_name -e &quot;DROP TABLE @@&quot; </span></pre></div> </td></tr></table>
1
2
3
4
5
6
--- 
+++ 
@@ -0,0 +1,3 @@
+mysql -u root -D db_name -e "show tables" -s | 
+  egrep "^wp_2_" | 
+  xargs -I "@@" echo mysql -u root -D db_name -e "DROP TABLE @@"