コード例 #1
0
  private EmbeddedMysql addSchema(final SchemaConfig schema) {
    Charset effectiveCharset = schema.getCharset().or(config.getCharset());

    getClient(SystemDefaults.SCHEMA)
        .executeCommands(
            format(
                "CREATE DATABASE %s CHARACTER SET = %s COLLATE = %s;",
                schema.getName(), effectiveCharset.getCharset(), effectiveCharset.getCollate()),
            format("GRANT ALL ON %s.* TO '%s'@'%%';", schema.getName(), config.getUsername()));

    getClient(schema.getName()).executeScripts(schema.getScripts());

    return this;
  }
コード例 #2
0
  protected EmbeddedMysql(final MysqldConfig config) {
    this.config = config;
    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(config.getVersion()).build();
    this.executable = new MysqldStarter(runtimeConfig).prepare(config);

    try {
      executable.start();
      getClient(SCHEMA)
          .executeCommands(
              format(
                  "CREATE USER '%s'@'%%' IDENTIFIED BY '%s';",
                  config.getUsername(), config.getPassword()));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }