# How to delete multiple databases using MYSQL

> Several methods to delete multiple databases from a testing environment. You can use plain SQL or stored procedures. Here's how.

- URL: https://graffino.com/til/how-to-delete-multiple-databases-in-mysql-maria-db-using-just-sql
- Author: Zeno Popovici
- Channel: mysql
- Published: 2020-12-15
- Updated: 2021-11-15

When you have to delete 100+ databases created by a botched deployment script you have a few options available:

## 1. Plain SQL
You'll have to run this query and then copy paste the result into a second query.

```sql

SELECT
	GROUP_CONCAT( CONCAT( 'DROP DATABASE `', SCHEMA_NAME, '`;' ) SEPARATOR ' ' ) AS DELETE_QUERY
FROM
	information_schema.SCHEMATA 
WHERE
	SCHEMA_NAME LIKE '{DBNAME}%'

```


## 2. Stored procedure
This allows you to create a stored procedure that will run your query in one go.

```sql
CREATE PROCEDURE clean () BEGIN

	SET @QUERY := (
		SELECT
			CONCAT( 'DROP DATABASE `', SCHEMA_NAME, '`;' ) 
		FROM
			`information_schema`.`SCHEMATA` 
		WHERE
			SCHEMA_NAME LIKE '{DBNAME}%' 
			LIMIT 1 
		);
	PREPARE stmt 
	FROM
		@QUERY;
	EXECUTE stmt;
	DEALLOCATE PREPARE stmt;
	
END;
CALL clean ();
DROP PROCEDURE clean;
```
