skip to Main Content

I am trying to empty the database of any data, while keeping the relationships and tables as they are

I have no idea if my thinking is right or wrong

3

Answers


  1. Yes, you just run mysqldump with –no-data

    mysqldump --no-data -u someuser -p mydatabase
    

    You can save it to a .sql file and then drop your database
    Then you restore it from the dump

    Login or Signup to reply.
  2. truncate table_name;
    

    table_name is the table you want to delete all data in it.
    truncate only works on tables, so you need to execute truncate table one by one.

    Login or Signup to reply.
  3. Use truncate to all table :

    mysqldump -d -uuser -ppass --add-drop-table databasename > databasename.sql
    mysql -uuser -ppass databasename < databasename.sql
    

    or you can read this, similar problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search