简体   繁体   中英

Spring Boot - spring.jpa.hibernate - how to call with sudo?

I am working on a project for my work and the way they setup the mysql server to be able to connect I need to do

sudo myqsl -p

When I try to launch my spring boot app, it fails to connect to the mysql server.. How can I tell jpa hibernate to call the mysql with sudo rights? Is it even possible ?

I have tried launching the spring boot jar with sudo and it doesn't carry on to the mysql connection somehow

My application.properties contain those credentials

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/mood
spring.datasource.username=user
spring.datasource.password=password

The database mood exists on the server and the user also exist. I can connect via ssh without any issues, using sudo.

Any help is appreciated!

No, it's not possible to connect to mysql in JPA with sudo rights, but you should be able to connect using the JDBC Connection string:

jdbc:mysql://localhost:portnumber:username:password

As a test, why don't you code a little class that will connect to the database, perform a simple SELECT statement and bring back a result set.

You shouldn't have to connect to the mysql client with sudo, but I infer that when you say "they setup" you mean the system admins. Ask them nicely to set up the mysql client as a normal command.

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