Testcontainers-java: MariaDB: Access denied for user 'test'@'%' to database.

Created on 23 Oct 2018  路  6Comments  路  Source: testcontainers/testcontainers-java

_org.testcontainers.mariadb version: 1.9.1_
jdbc-url property:
url: "jdbc:tc:mariadb:latest://localhost:3306/test?TC_INITFUNCTION=packagepath.TestContainersDatabaseDescriptor::createDatabase"
And TestContainersDatabaseDescriptor class

public class TestContainersDatabaseDescriptor {

    @Language(value = "MariaDB")
    private static final String CREATE_DATABASE = "CREATE DATABASE dictionaries CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";

    public static void createDatabase(Connection connection) throws SQLException {
        connection.createStatement().execute(CREATE_DATABASE);
    }

}

As the result:
Caused by: java.sql.SQLException: Access denied for user 'test'@'%' to database 'dictionaries'

modulejdbc resolutioacknowledged typfeature

Most helpful comment

@maystrovyy I would like to do the same (create a new database) with MySQL. Do you have any solution or just closed the ticket?

All 6 comments

Hey @maystrovyy, thanks for raising an issue.
As far as I see it, using the JDBC driver will run the init script/function as the default user and not as root. So the user is missing the privileges to create a new database.

Maybe you can solve your use case by using the MariaDBContainer container and the root user?

Else you can also try to use the root user for everything:
jdbc:tc:mariadb:latest://localhost:3306/test?user=root?password=test?TC_INITFUNCTION=packagepath.TestContainersDatabaseDescriptor::createDatabase. TBH I'm not sure we honor those params when parsing the URL though,

See #585

Hi @kiview , thanks for fast answer.

Else you can also try to use the root user for everything:
jdbc:tc:mariadb:latest://localhost:3306/test?user=root?password=test?TC_INITFUNCTION=packagepath.TestContainersDatabaseDescriptor::createDatabase

Unfortunately, your solution didn't help, the result is still the same.
Acquainted with #585, I will try to find another solution, thanks)

@maystrovyy I would like to do the same (create a new database) with MySQL. Do you have any solution or just closed the ticket?

It works with root user:
new MariaDBContainer<>().withUsername("root").withPassword("").withDatabaseName("test-db")

If any one interested:
jdbc:tc:mariadb:latest://localhost/DB-NAME?user=root?password=&
Did the trick for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

denis-zhdanov picture denis-zhdanov  路  3Comments

dabraham02124 picture dabraham02124  路  3Comments

eksd picture eksd  路  3Comments

aruizca picture aruizca  路  4Comments

michael-simons picture michael-simons  路  3Comments