Reputation: 10973
I use JDBC and Spring Boot 2.2.2 to connect to a MariaDB instance. The login fails with this message:
Caused by: java.sql.SQLInvalidAuthorizationSpecException: Could not connect to address=(host=server.company.domain)(port=3306)(type=master) : Access denied for user 'user'@'server.company.domain' (using password: YES)
When I run mysqldump -u"user" -p"password" -h server.company.domain dbname
this works just fine !
jdbc:mariadb://server.company.domain:3306/dbname
localhost
instead of the server nameUpvotes: 1
Views: 5670
Reputation: 10973
I ran a short SHOW GRANTS;
via the mysql
command which is able to connect to the database. The output gave me this:
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY PASSWORD 'nonono' REQUIRE SSL WITH GRANT OPTION
The relevant part is REQUIRE SSL
: connections to that server need to be done encrypted.
When I checked the files in /etc/my.cnf.d/
I found a file containing (amongst others) these lines:
[server]
ssl=1
ssl-cert=/path/to/certificate/cert.pem
By googling a bit I found this link which describes how to set the JDBC driver to use ssl. It also explains to you why you perhaps should think twice before setting trustServerCertificate
to true
.
My spring.datasource.url
now looks like this:
jdbc:mariadb://server.company.domain:3306/dbname?useSSL=true&trustServerCertificate=true&serverSslCert=/path/to/certificate/cert.pem
To put it short: Access denied for user
doesn't tell the complete story. It makes you think that your password might be wrong but you are denied for other reasons.
Upvotes: 1
Reputation: 2850
It seems like you are having trouble with MariaDB, not spring-boot itself. I suggest you to follow this links: https://mariadb.com/kb/en/configuring-mariadb-for-remote-client-access/, and come back if it didn't solve your problem, with what you tried, and what didn't work.
Upvotes: 2