I try to include a MySQL-DB in my project.
I've installed MySQL program, created a DB (schema) and set password and username for the access-authentification.
Included pom-file dependencies and so on.
Now I'm stuck with my application.properties:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/asndb
spring.datasource.username=root
spring.datasource.password=asnTeam1
spring.jpa.hibernate.ddl-auto=create
In the MySQL Manager I can see all properties from my models, so the connection should work, right?
What do I wrong? Do I need the MySQL client?
UPDATE changed application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/asndb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=asnTeam1
spring.jpa.hibernate.ddl-auto=create
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.platform=mysql
spring.datasource.schema=schema-mysql.sql
spring.datasource.data=data-mysql.sql
spring.datasource.initialize=true
spring.datasource.continue-on-error=true
Now I want to open with MySQL client my data.sql file. But there are erros in my sql syntax. Following an insert statement:
INSERT INTO USER (FIRST_NAME, LAST_NAME, USERNAME, PASSWORD, USER_ROLE) VALUES('Admin', 'Istrator', 'admin', '$2a$10$W9xQIwa/FstPUvcbzJXnQ.XjVdTyIcCEp.g6VCq1gYuSsQNjJjbJG', 'ADMIN')
INSERT INTO USER (FIRST_NAME, LAST_NAME, USERNAME, PASSWORD, USER_ROLE) VALUES('Bernd', 'Menia', 'bernd', '$2a$10$6dQcayeT/JAFvgFvzIjlcew5z9cmdCrGlv57.BGnIKvPXTDsQm7hG', 'PARENT')
INSERT INTO PARENT (FAMILY_STATUS, LOCATION, POSTCODE, STREET_NAME, IMG_NAME, STATUS, ID) VALUES ('MARRIED', 'Innsbruck', '6020', 'Bahnhofstraße', 'john.jpg',TRUE, SELECT ID FROM USER WHERE USERNAME = 'bernd')
What do I wrong?
SOLUTION:
insert the larger application.properties from above and for a persistent DB comment out the ddl-auto=true
and initialize=true
after the first spring-boot.
User
is a reserved keyword in MySQL, so it is not allowed to use.
to fill a mySQL DB with data.sql file from spring-app is not possible, so I open the file via MySQL-Workbench and execute the statements.