close
Breaking news

All those who have shared hosting we have sometimes had the need to delete the c...read more

Delete everything you need in a MySQL database

base de datos poner where

All those who have shared hosting we have sometimes had the need to delete the contents of a database. How simple it is to completely remove the database and re-create it, but sometimes this is not possible because we don't have permissions to do so.

 

The following query will allow this us whenever we have access to "information_schema" (which is very likely).

We must first access the database that you want to purge

USE CAMBIAR_POR_LA_BASE_DE_DATOS_QUE_QUIERAS_PURGAR;

And then execute the following Query:

SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN = 32768;
SET @tables = NULL;
SELECT GROUP_CONCAT(''', table_name, ''') INTO @tables
FROM information_schema.tables
WHERE table_schema = (SELECT DATABASE());
SELECT IFNULL(@tables,'dummy') INTO @tables;

SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1;

This query generates a subquery of the style "DROP TABLE IF EXISTS t1, t2,…"

Tags: ,

No Comments

Leave a reply

Post your comment
Enter your name
Your e-mail address

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Story Page

Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies. ACEPTAR

Aviso de cookies