java - JDBC in groovy script mysql access denied even though permissions are set up correctly -


i have written following groovy script connect mysql database:

this.class.classloader.rootloader.addurl(new file("/root/mysql-connector-java-5.1.35.jar").tourl())  import groovy.sql.*  def username = 'root' def password = 'password' def database = 'database' def server = 'localhost'  def db = sql.newinstance("jdbc:mysql://$server/$database", "$username", "$password", 'com.mysql.jdbc.driver') 

when run this:

groovy sqlcon.groovy 

i following error:

caught: java.sql.sqlexception: access denied user 'root'@'localhost' (using password: yes) @ query.run(query.groovy:10)

but can log in mysql database locally using same credentials , output from

select host, user mysql.user; 

looks this:

+-----------+------------------+ | host      | user             | +-----------+------------------+ | 127.0.0.1 | root             | | localhost | root             | +-----------+------------------+ 

does have idea causing behaviour ? appreciated :)

i'm not sure, may need specify mysql port connection.

try this:

def username = 'root' def password = 'password' def database = 'database' def server = 'localhost:3306'  def db = sql.newinstance("jdbc:mysql://$server/$database", "$username", "$password", 'com.mysql.jdbc.driver') 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -