Reputation: 506
I try to create JpaTest, for this I need a container with mariaDb. So I try create it:
private static final String CONTAINER_IMAGE_NAME = TestcontainersConfiguration.getInstance()
.getEnvVarOrProperty("mariadb.container.image", "mariadb:10.2.18");
private static final MariaDBContainer<?> PRIMARY_MARIADB_SQL_CONTAINER = new MariaDBContainer<>(
DockerImageName
.parse(CONTAINER_IMAGE_NAME )
.asCompatibleSubstituteFor("mariadb")
)
.withDatabaseName("db")
.withUsername("test")
.withPassword("password")
.withPrivilegedMode(true)
.withInitScript("mariadb/init.sql");
Without last withInitScript
all work fine, but when I add sql I have an error:
Caused by: java.sql.SQLSyntaxErrorException: Access denied for user 'test'@'%' to database 'test_schema'
And in my init.sql I have:
CREATE SCHEMA IF NOT EXISTS test_schema;
GRANT ALL PRIVILEGES ON test_schema.* TO 'test'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Upvotes: -1
Views: 665
Reputation: 246
Try replacing .withInitScript("mariadb/init.sql");
with withCopyFileToContainer
setting for init-script execution
.withCopyFileToContainer(
MountableFile.forClasspathResource("mariadb/init.sql"),
"/docker-entrypoint-initdb.d/"
);
Upvotes: 0