How to delete structure and data from mysql database

Asked

Viewed 8,281 times

-3

How to perform a complete deletion of a database structure mysql?

I need to delete all the entidades, tabelas, procedures, I want to keep only the name of the database, without any table or data or anything else linked to that database.

There is a command that I do such a procedure?

  • 2

    DROP database <nome> ?

  • Will I keep the name of the bank? It will remain registered?

  • 2

    Everything will be removed! what is the purpose of keeping the name?

  • I need to keep the name of the bank because I am doing experiments with an application called GLPI that is having error so my logistics to find the solution to a problem is to install the various versions of the system until finding a solution.

  • @rray knows some command that does this?

  • @Sergio, can you help me?

  • 1

    Using only Mysql does not make something as automated as this, using some script can facilitate this task. I don’t know any commands that perform DROP on all objects in the database without removing it, you can see this by the answers, each one tries to solve the limitation in a way.

  • I understand. I’ll find a solution. Thank you anyway.

  • 1

    Perhaps the most automated (I imagine) way is to create a project that manages drop and perform one by one.

Show 4 more comments

3 answers

1

You can kill the entire database and redo it with the same name:

DROP database 'meudatabase';
CREATE database 'meudatabase';

If you have a scritp to create the entire database better yet, something like:

#Criando DATABASE
CREATE DATABASE `meudatabase`;

#Criando a tabela TABELA1
CREATE TABLE `meudatabase`.`TABELA1` (
...
  • Thank you, that I’m doing, but I want to try what was asked.

0

Delete all tables from the database:

SELECT concat('DROP TABLE IF EXISTS ', TABLE_NAME, ';') FROM information_schema.TABLES;
  • This command is not what I’m asking.

  • 3

    @what you’re asking for?

  • Come on, baby, I’m serious?

  • This command does: delete all tables in the database, if that’s not what you meant, specify your question better. @durtto

  • My question is specified Bia. Specify what your question is.

  • I need to "clean" the structure and data of the database, but I need to keep it, I don’t want to drop the bank, I want to drop the structure of the database.

  • 1

    The command she posted drops the tables friend! If her answer does not suit you use @Ricardo’s command before your question reaches 300 negative votes!

  • 2

    The command(SELECT) generates the DROP TABLE of Databases, missing a WHERE to specify which, after generated you need to execute the commands one by one. I didn’t understand the downvote.

  • I don’t care if my question gets downvotes. I need to solve my problem. But unfortunately no one has captured what I need.

  • @rray that same, I need to perform everything in one operation.

  • 1

    @durtto, when there is much comment asking for clarification in the question and when the answers do not answer is because your question is not clear. Instead of giving explanations in comments, prefer to edit the question to improve overall understanding.

  • 1

    @My question is a great example that shows that people are reading only the first line. In the second and other lines I explain what I want. And another thing, the best answer is in the comments, which says that the command I seek does not exist.

Show 7 more comments

0

Oops, I found an answer in the SOEN, from a look. https://stackoverflow.com/a/8912749/2161286, I imagine it helps you.

drop

mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "drop table $table" DATABASE_NAME; done

truncate

mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "truncate table $table" DATABASE_NAME; done

  • Could you please explain to me what this command does?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.