How to truncate All Tables in MySQL from the command line
search cancel

How to truncate All Tables in MySQL from the command line

book

Article ID: 250542

calendar_today

Updated On:

Products

DX NetOps CA Spectrum

Issue/Introduction

I would like to truncate all tables from a MySQL database. Is there a syntax in one command?

Environment

Release : 21.2

Component : Spectrum Reporting

Resolution

 

./mysql --defaults-file=../my-spectrum.cnf -uroot -pMySqlR00t ddmdb -Nse "show tables" | while read table; do ./mysql --defaults-file=../my-spectrum.cnf -uroot -pMySqlR00t ddmdb -e "truncate table $table"; done


./mysql --defaults-file=../my-spectrum.cnf -uroot -pMySqlR00t archive -Nse "show tables" | while read table; do ./mysql --defaults-file=../my-spectrum.cnf -uroot -pMySqlR00t archive -e "truncate table $table"; done