Sonar fails to connect to database

喜欢而已 提交于 2019-12-23 08:59:20

问题


I am using the following software:

  • Sonar 3.4.1
  • Mysql 5.1
  • Maven 2.2.1
  • Tomcat 7

I have a pom.xml file which I am trying to execute with Sonar but getting the follwing error.

[INFO] Building asgard-bpm
[INFO] task-segment: [sonar:sonar] (aggregator-style)
[INFO] -----------------------------------------------------------------------
[INFO] [sonar:sonar {execution: default-cli}]
[INFO] Sonar host: http://{host:8080}/sonar
[INFO] Sonar version: 3.4.1
[INFO] Execute: org.codehaus.sonar:sonar-maven-plugin:3.4.1:sonar
[INFO] [sonar:sonar {execution: default-sonar}]
[INFO] [14:34:54.474] Load project settings
[INFO] [14:34:54.552] Install plugins
[INFO] [14:34:56.674] Apply project exclusions
[INFO] [14:34:56.674] Install JDBC driver
[WARN] [14:34:56.736] H2 database should be used for evaluation purpose only
[INFO] [14:34:56.736] Create JDBC datasource for jdbc:h2:tcp://host/sonar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Can not execute Sonar

Embedded error: Fail to connect to database
Connection refused: connect

I have created a user in the DB with the username as 'sonar' and password as 'sonarsonar'.

Created schema named 'sonar' and granted all privileges also.

BELOW IS THE PROPERTIES SET IN THE SONAR.properties file.

sonar.web.host:                           {127.0.0.1}
sonar.web.port:                           80
sonar.web.context:                        /


sonar.jdbc.username:                       sonar
sonar.jdbc.password:                       sonarsonar

sonar.jdbc.url:                                      {jdbc:mysql://host:3306/sonaruseUnicode=true&characterEncoding=utf8}
sonar.jdbc.driverClassName:                com.mysql.jdbc.Driver
sonar.jdbc.validationQuery:                select 1

Can someone please tell me how to resolve this error.


回答1:


Your Sonar is not connected to your database. Check your <.m2/settings.xml> file. You need to change the < sonar.jdbc.url > under the properties :

<!-- H2 - Default DB -->
<!-- <sonar.jdbc.url>
       jdbc:h2:tcp://localhost:9092/sonar
     </sonar.jdbc.url> -->
<!-- MySQL DB -->
    <sonar.jdbc.url>
      jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8
    </sonar.jdbc.url>



回答2:


Configure "sonar-runner.properties" to connect to MySQL Database.

Try uncommenting this lines:

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.sourceEncoding=UTF-8


来源:https://stackoverflow.com/questions/16936735/sonar-fails-to-connect-to-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!