Skip to content

Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation #4544

@rommy2015

Description

@rommy2015
  • sql/init_db.sql

CREATE DATABASE IF NOT EXISTS 'db_test; CREATE USER test@%IDENTIFIED BY 'test'; GRANT ALL PRIVILEGES ONdb_test.* TO test@%;

  • in Spring boot
    `
    ....
    String pathToInitScripts = "sql";

     MY_SQL_CONTAINER = new MySQLContainer<>(postgres)
             .withDatabaseName("db_test")
             .withUsername("test")
             .withPassword("test")
             .withInitScript(pathToInitScripts + "/init_db.sql")
             .withReuse(true);
    
     MY_SQL_CONTAINER.start();
    

@DynamicPropertySource
public static void registerPgProperties(DynamicPropertyRegistry propertyRegistry) {

    String jdbcUrl = MY_SQL_CONTAINER.getJdbcUrl();
    System.out.println(jdbcUrl);

    propertyRegistry.add("spring.datasource.url", getMySqlContainer()::getJdbcUrl);
    propertyRegistry.add("db_test", getMySqlContainer()::getDatabaseName);
    propertyRegistry.add("spring.datasource.username", getMySqlContainer()::getUsername);
    propertyRegistry.add("spring.datasource.password", getMySqlContainer()::getPassword);
}

`

I have gotten errors:

Caused by: org.testcontainers.ext.ScriptUtils$ScriptStatementFailedException: Script execution failed (sql/init_db.sql:2): CREATE USER test@% IDENTIFIED BY 'test' at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:49) at org.testcontainers.delegate.AbstractDatabaseDelegate.execute(AbstractDatabaseDelegate.java:34) at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:362) ... 71 more Caused by: java.sql.SQLSyntaxErrorException: Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)

How can this be fixed. ? I can't create tables in testcontainer, I can't use create and alter, create schema- commands and others because of an access error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions