MySQL/MariaDB common commands
Using Bash/Shell
Create a backup first! Before you do anything.
We all know using mysqldump or mariadb-dump to create a backup of the database (schema + data). But you can use it to drop tables if you need to clean up the database.
In case you don't here it is:
mysqldump -u <username> \
-p <database_name> \
-h <host> <database> \
> backup.sql
It is not recommended to use credentials in the command line, but you could.
Ok, back to the topic; here is how using Bash/Shell only:
mysqldump -u <username> \
-p <database_name> \
-h <host> <database> \
| grep ^DROP \
| mysql -u <username> \
-p <database_name> \
-h <host> <database>
Replace mysqldump with mariadb-dump if you are using MariaDB. Although, mysql might be an alias for mariadb-dump, depending on your system.
The logic is simple, get a database dump, which contains the DROP TABLE statements, then use grep to filter out only lines that start with "DROP" and pipe it to the mysql command to execute those statements.
The expected result should be an empty database. Please don't do this on PRODUCTION database, unless you are sure what you are doing.
Creating a database dump and compressing it with the same command
Database dumps can be huge. You can compress them on the fly using gzip or tar:
mysqldump \
-u <username> \
-p <database_name> \
-h <host> <database> \
| gzip > backup.sql.gz