Spring Boot MariaDB connection and issues

Updated:

Configuration

In application.properties:

spring.datasource.url=jdbc:mariadb://[SERVER]:[PORT]/[DATABASE_NAME] 
spring.datasource.username=[USER_NAME] 
spring.datasource.password=[PASSWORD] 
spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect 

example:

spring.datasource.url=jdbc:mariadb://localhost:3306/database_example 
spring.datasource.username=my_user 
spring.datasource.password=my_password 
spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect 

Possible errors:

2021-01-31 20:18:04.525 WARN 14261 --- [nio-8080-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1046, SQLState: 3D000 2021-01-31 20:18:04.526 ERROR 14261 --- [nio-8080-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : (conn=26) No database selected

The DATABASE_NAME was not in the url. The database name is called 'schema' in IntelliJ and 'catalog' in @Table.

Solve the Access Denied for User 'root'@'localhost' error

You just installed MySQL or MariaDB and you receive this error: Access Denied for User 'root'@'localhost' (using password: YES) - No Privileges. How to solve it? In many websites there are a lot of different approaches and solutions, often with 5 or more steps to do.

A working solution for old systems is to execute ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

if you get: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'BY 'password'' at line 1 ... then your version of MariaDB is not compatible with this solution.

In this case is better to use

sudo mysql 
 
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password USING PASSWORD('password');` this should correctly reset your password. 

WebApp built by Marco using SpringBoot 3.2.4 and Java 21, in a Server in Switzerland