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

前端 未结 6 1241
醉酒成梦
醉酒成梦 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 02:56

    From electrictboolbox.com/mysqldump-schema-only:

    Dumping the database structure for all tables with no data Add the -d flag to signify that no data should be included in the output like so, where "mydatabase" is the name of the database to dump, and "someuser" is the login name used to connect to the database. The following command will dump the table structure for all tables in the specified MySQL database:

    $ mysqldump -d -u someuser -p mydatabase
    

    The -d flag says not to include data in the dump. Alternatively you can use --no-data instead if you find that easier to remember:

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

    The -u flag indicates the username and the -p flag that a password will be supplied. After pressing you will be prompted for the password.

    Alternatively, the password can be supplied on the command line, but there must be no space between the -p flag and the password. For example, if the password was "apples" do this:

    $ mysqldump --no-data -u someuser -papples mydatabase
    $ mysqldump -d -u someuser -p mydatabase > mydatabase.sql # This will output to a sql file
    

提交回复
热议问题