问题
I am trying to add Sonar to my Continuous Integration build system. I am using ANT as my build script and I am using the sonar-ant-task-1.1.jar for sonar to generate the reports based on my source code in SVN.
Problem When the build runs and hits the sonar ant task I get the exception as follows:
Caused by: java.sql.SQLException: Access denied for user 'sonar'@'glassfishdev.ccs.local' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
at org.sonar.jpa.session.DriverProxy.connect(DriverDatabaseConnector.java:160)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.sonar.jpa.session.DriverDatabaseConnector.getConnection(DriverDatabaseConnector.java:95)
at org.sonar.jpa.session.AbstractDatabaseConnector.testConnection(AbstractDatabaseConnector.java:185)
... 40 more
What I have done
1. Install MySQL database.
2. Create the sonar database, sonar user, and grant permissions by using the script provided in the sonar installation
**CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;**
3. Added the following to my build script
4. Added the following external variables in Jenkins Freestyle build project
sonar.jdbc.url=jdbc:mysql://10.120.21.12:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://10.120.21.12:9000/
5. I was also available to connect to the database through my sql client tool to verify that the database, user and permissions statements were executed correctly.
However when Jenkins runs the build it does not seem to know how to connect to the MySQL database.
Any thoughts?
回答1:
The solution was to run the following command:
GRANT ALL ON *.* TO 'sonar'@'%';
回答2:
The right solution is this:
GRANT ALL PRIVILEGES ON `sonar`.* TO 'sonar'@'localhost';
As explained here, connections to localhost occur over a UNIX domain socket. You are likely logging in as an anonymous user to localhost (e.g. ''@localhost).
回答3:
I just tried it with sonar 4.5.2 with grants only on sonar.* and its definitely not working.
It looks like sonarqube requires additionnal privileges to work, personnaly i haven't identified which ones yet, and i'm still using a grant all on the database.
来源:https://stackoverflow.com/questions/7247945/unable-to-access-sonar-mysql-database-caused-by-java-sql-sqlexception-access-d