简体   繁体   中英

How can I import .sql file in my MYSQL DB using spring boot?

I need to develop a service which will able to execute uploaded .sql file on the MySQL DB. Means, I will upload a .sql file from front-end and hit my URL which will then excecute that .sql file on my DB and procced accordingly.

I searched for solutions and found some solutions as well and I didn't get the exact view for the same. I am using JPA query for implementing the said process.

Repository

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "IMPORT TABLE FROM ?1")
    void inserMarketPriceTable(MultipartFile file);

Please help me out through this. Thanks in advance!

In my company we use flyway to do something similar. We upload the db scripts in a specific folder and then use a bash script/jenkins task to execute the changes. If you're familiar with the Laravel Migration tool, it kind of works the same way. The CLI doesn't require much installation or configuartion.

Flyway link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM