

def _clone_test_db(self, number, verbosity, keepdb=False):
    qn = self.connection.ops.quote_name
    source_database_name = self.connection.settings_dict['NAME']
    target_database_name = self.get_test_db_clone_settings(number)['NAME']
    with self._nodb_connection.cursor() as cursor:
        try:
            cursor.execute(('CREATE DATABASE %s' % qn(target_database_name)))
        except Exception as e:
            if keepdb:
                return
            try:
                if (verbosity >= 1):
                    print(('Destroying old test database for alias %s...' % (self._get_database_display_str(verbosity, target_database_name),)))
                cursor.execute(('DROP DATABASE %s' % qn(target_database_name)))
                cursor.execute(('CREATE DATABASE %s' % qn(target_database_name)))
            except Exception as e:
                sys.stderr.write(('Got an error recreating the test database: %s\n' % e))
                sys.exit(2)
    dump_cmd = DatabaseClient.settings_to_cmd_args(self.connection.settings_dict)
    dump_cmd[0] = 'mysqldump'
    dump_cmd[(- 1)] = source_database_name
    load_cmd = DatabaseClient.settings_to_cmd_args(self.connection.settings_dict)
    load_cmd[(- 1)] = target_database_name
    dump_proc = subprocess.Popen(dump_cmd, stdout=subprocess.PIPE)
    load_proc = subprocess.Popen(load_cmd, stdin=dump_proc.stdout, stdout=subprocess.PIPE)
    dump_proc.stdout.close()
    load_proc.communicate()

dataset/ETHPy150Open django/django/django/db/backends/mysql/creation.py DatabaseCreation._clone_test_db/original