Question

I want All CREATE statements of MySql Tables in 1 query result.

For example, INFORMATION_SCHEMA contains all table names,comments etc. but where are the CREATE statements are stored in MySql ? can it be retrieved in one query for all tables ?

Currently i am retrieving TABLE ddl as below for 1 table. I have 100's of tables so i can repeat the same everytime which is time taking process

show create table row_format;
Was it helpful?

Solution

mysqldump -h localhost -u root -p --no-data --compact  some_db


mysqldump -d --compact --compatible=mysql323 ${dbname}|egrep -v "(^SET|^/\*\!)"

How do I use mysqldump to export only the CREATE TABLE commands

OTHER TIPS

I needed this today, and the mysqldump answer generated me a .sql file that I could not import: it declared full CREATE TABLE statements with foreign keys pointing to tables it had not declared yet.

Instead, I used Liquibase:

  1. Download MySQL Connector/J (pick Platform Independent): https://dev.mysql.com/downloads/connector/j/

  2. From the directory where you downloaded the connector jar, create a liquibase.properties file and edit it like so:

outputDefaultSchema=true
includeSchema=true
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/replace_with_your_db
username=replace with your MySQL user
password=replace with your MySQL password
classpath=full path of the MySQL connector, for instance C:\mysql-connector-java-8.0.21.jar
  1. Install Liquibase then run:
liquibase --changeLogFile=schema.mysql.sql generateChangeLog

This will generate SQL commands for your schema, all in the right order.

For instance:

CREATE TABLE address (id BIGINT AUTO_INCREMENT NOT NULL, line VARCHAR(128) NULL, owner_id BIGINT NOT NULL);
CREATE TABLE person (id BIGINT AUTO_INCREMENT NOT NULL, name VARCHAR(64) NOT NULL);
ALTER TABLE address ADD CONSTRAINT fk_address_person FOREIGN KEY (owner_id) REFERENCES person (id) ON UPDATE RESTRICT ON DELETE RESTRICT;

Someone just showed me an easier way.

  1. Highlight all the tables
  2. Right click.
  3. Select 'Copy to Clipboard' and then 'Create statements'.
  4. Go to a text editor and paste and everything is there.
  1. Select the Database required
  2. Select the tables (Check all for all tables) you want to SHOW CREATE TABLE
  3. Click on dropdown With Selected: and select Show create
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top