copy database structure without data in mysql (with empty tables)

前端 未结 6 1220
醉酒成梦
醉酒成梦 2021-01-31 02:36

Is there any way to copy database structure without data in MySQL, so the new database will be the same as it is copied from, but with empty tables.

After getting some s

6条回答
  •  伪装坚强ぢ
    2021-01-31 03:06

    You can backup you MYSQL database structure with

    mysqldump -u username –p  -d database_name > backup.sql
    

    (You should not supply password at command line as it leads to security risks.MYSQL will ask for password by default.) And you can create create tables in database with

    mysql -u username -p new_database < backup.sql
    

    Now you can use pipe to give the output of first command as output for second one and you will no longer need backup.sql

    mysqldump -u username –p  -d database_name|mysql -u username -p new_database
    

    All tables in will be created in new_database without data.

提交回复
热议问题