I have 100 tables, 40,000 rows in each table. I want to go into MySQL and delete all rows from all tables.
...in 1 statement, if p
I had to restore a backup which was missing the create statements. So I restored an older backup but I had to get rid of the data. This oneliner helped me truncate everything.
mysql -u user -ppass -NBe "SELECT 'SET foreign_key_checks = 0;' UNION SELECT CONCAT('TRUNCATE TABLE myschema.', table_name, ';') FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'myschema' AND table_type = 'BASE TABLE'" | mysql -u user -ppass
For better readability again with line breaks:
mysql -u user -ppass -NBe "SELECT 'SET foreign_key_checks = 0;'
UNION SELECT CONCAT('TRUNCATE TABLE myschema.', table_name, ';')
FROM INFORMATION_SCHEMA.tables
WHERE table_schema = 'myschema' AND table_type = 'BASE TABLE'"
| mysql -u user -ppass
be sure to use the string without line breaks and replace myschema with your table schema and set the correct login credentials or host for mysql process.