Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-7099

CREATE DATABASE xxxx LIKE yyyy

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      Hi guys
      I'm doing something that i do many times... but now i asked my self... why i'm doing this?! what i'm doing???

      mysqldump some_database (without data) > sql.file
      mysql sql.file to some new database...

      instead of this, why shouldn't i execute something like:

      CREATE DATABASE {new_database} [LIKE/CLONE] {old_database}

      this will do something like ....

      [LIKE]:
       
      SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA="{old_database}";
      CREATE TABLE {new_database}.{TABLE_NAME} LIKE {old_database}.{TABLE_NAME}
       
      [CLONE]:
       
      SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA="{old_database}";
      CREATE TABLE {new_database}.{TABLE_NAME} LIKE {old_database}.{TABLE_NAME};
      INSERT INTO {new_database}.{TABLE_NAME} SELECT * FROM {old_database}.{TABLE_NAME};

      this save me from using shell (mysqldump/mysql) or heidisql or any other problem of dump, filesystem (saving the sql file with a nice user privilege chmod 777 , and after a rm file)
      i think it's "easy" (must check what to do with foreign key and locks), i didn't checked how to create table like execute, but i think i could take a look, with a bit of time

      Attachments

        Activity

          People

            Unassigned Unassigned
            rspadim roberto spadim
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.