2021年1月16日星期六

Spring Boot can't create automatically database (with Jdbc + Mysql)

I created the files schema.sql and data.sql in the "resources" folder to create automatically a database called "spring" to store users and authorities, but I did not found it Mysql WorkBench !! Here's the sql scripts :

schema.sql

create database spring;    CREATE TABLE IF NOT EXISTS `spring`.`users` (      `id` INT NOT NULL AUTO_INCREMENT,      `username` VARCHAR(45) NOT NULL,      `password` VARCHAR(45) NOT NULL,      `enabled` INT NOT NULL,      PRIMARY KEY (`id`));    CREATE TABLE IF NOT EXISTS `spring`.`authorities` (      `id` INT NOT NULL AUTO_INCREMENT,      `username` VARCHAR(45) NOT NULL,      `authority` VARCHAR(45) NOT NULL,      PRIMARY KEY (`id`));  

data.sql

INSERT IGNORE INTO `spring`.`authorities` VALUES (NULL, 'tom', 'write');  INSERT IGNORE INTO `spring`.`users` VALUES (NULL, 'tom', '123456', '1');  

and application.properties

spring.datasource.url=jdbc:mysql://localhost/spring?serverTimezone=UTC  spring.datasource.username=root  spring.datasource.password=password  spring.datasource.initialization-mode=always  
https://stackoverflow.com/questions/65755947/spring-boot-cant-create-automatically-database-with-jdbc-mysql January 17, 2021 at 07:54AM

没有评论:

发表评论