Truncate database mysql

Truncate database mysql

Blog Bustle 02/03/2020

Truncate database mysql is an easy process to empty mysql database. Be careful before truncate database because we will not able to retrieve our data stored in database. All tables will get deleted after truncate database.

Truncate database mysql steps:

Step 1: Take your mysql database backup whom you want to empty.(Optional)

Step 2: Drop database.

Step 3: Create new database with the same name.

To take database backup in optional. But if you think you may need this database backup in future, it is important.

For example, i have student database. I want to empty student database. So what will be my truncate database mysql steps?

1. First i will take backup of student database.

I am using local server. I am going to take student database backup from command line.

Mysql database backup syntax

mysqldump -u [username] -p[password] [database_name] > [dump_file_name.sql]

In my case username is root, password is empty and i will save database backup by student.sql in d drive of computer and mysql database backup command will be

mysqldump -u root -p student > d:\student.sql

2. Now i will drop student database.

I have taken student database backup. Now i am going to delete student database and delete database query will be

drop database student;

3. I will create student database.

I have deleted student database. Now i am going to create student database and create database query will be

create database student;

truncate database mysql

So by following these steps we can easily truncate database mysql. Hope you like this tutorial.

Other important links

Mysql database backup

Delete table sql query

Create table sql query

Create database in mysql

Truncate database mysql searches:

Tags: #mysql