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.
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?
I am using local server. I am going to take student database backup from command line.
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
I have taken student database backup. Now i am going to delete student database and delete database query will be
drop database student;
I have deleted student database. Now i am going to create student database and create database query will be
create database student;
So by following these steps we can easily truncate database mysql. Hope you like this tutorial.