How to dump mysql table structure without data with a SQL query?

前端 未结 5 1604
遥遥无期
遥遥无期 2020-12-23 19:02

I need to export a mysql table, but it has like 5gb of entries, so I only want the structure. I am trying to do it from a simple php doing a sql query, how can I do that?

相关标签:
5条回答
  • 2020-12-23 19:30

    I'm not a MySQL expert by any means but the following site suggests using the -d or --no-data option of mysqldump:

    mysqldump -d -h localhost -u root -pmypassword databasename > dumpfile.sql
    

    It worked for me.

    0 讨论(0)
  • 2020-12-23 19:32

    It is already answered in the link below:
    MySql export schema without data

    Use the command below to take the structure or schema dump.

    mysqldump -u root -p --no-data dbname > schema.sql
    
    0 讨论(0)
  • 2020-12-23 19:35

    You can use SHOW CREATE TABLE for this.

    Shows the CREATE TABLE statement that creates the given table. The statement requires the SELECT privilege for the table. As of MySQL 5.0.1, this statement also works with views.

    E.g.:

    SHOW CREATE TABLE MyTablename
    
    0 讨论(0)
  • 2020-12-23 19:35

    if u have "MySQL Workbench" v6.0

    1) click on any table of the database.

    2) Right-click and select "Tables Maintenance"

    3) Under "Tables" tab, highlight the tables u want to export, right-click and select "Send to SQL Editor">"Create Schema"

    0 讨论(0)
  • 2020-12-23 19:47

    Depending on you exact requirements, something as simple as

    select * from table where 1=0
    

    might suffice.

    0 讨论(0)
提交回复
热议问题