【问题标题】:Sonar setup MYSQL声纳设置 MYSQL
【发布时间】:2015-07-29 22:03:02
【问题描述】:

我正在尝试将默认数据库更改为 MYSQL。我使用了一些教程,例如 http://laurenthinoul.com/how-to-change-sonar-default-database/。 Mysql 数据库创建并运行。

我的问题是文件夹中的文件 ..sonarqube\sonarqube-5.1.1\conf 默认文件 sonar.properties 所有配置都已注释我尝试取消注释 mysql 驱动程序,但它不起作用。我的问题是为什么注释默认数据库,以及如何更改为 Mysql。

# DATABASE
#
# IMPORTANT: the embedded H2 database is used by default. It is recommended for tests but not for
# production use. Supported databases are MySQL, Oracle, PostgreSQL and Microsoft SQLServer.

# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.
#sonar.jdbc.username=sonar
#sonar.jdbc.password=sonar

#----- Embedded Database (default)
# It does not accept connections from remote hosts, so the
# server and the analyzers must be executed on the same host.
#sonar.jdbc.url=jdbc:h2:tcp://localhost:9092/sonar

# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port=9092


#----- MySQL 5.x
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported.
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

然后我尝试访问 localhost:9000/setup 出现错误

迁移失败:发生错误,所有以后的迁移都取消了:ActiveRecord::JDBCError: 表'rule_tags'已经存在:CREATE TABLE rule_tags (id int(11) auto_increment PRIMARY KEY, tag varchar( 100)) 引擎=InnoDB 字符集 utf8 整理 utf8_bin 。 请检查日志。

日志:

2015.07.28 21:18:21 INFO  web[DbMigration] ==  AddRuleTags: migrating ====================================================
2015.07.28 21:18:21 INFO  web[DbMigration] -- create_table(:rule_tags, {})
2015.07.28 21:18:21 ERROR web[o.s.s.ui.JRubyFacade] Fail to upgrade database
An error has occurred, all later migrations canceled:

ActiveRecord::JDBCError: Table 'rule_tags' already exists: CREATE TABLE `rule_tags` (`id` int(11) auto_increment PRIMARY KEY, `tag` varchar(100)) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/jdbc/adapter.rb:183:in `execute'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/schema_statements.rb:109:in `create_table'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb:252:in `create_table'
    org/jruby/RubyKernel.java:2231:in `send'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:352:in `method_missing'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:328:in `say_with_time'
    jar:file:/E:/sonarqube/sonarqube-5.1.1/lib/server/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/1.8/benchmark.rb:293:in `measure'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:328:in `say_with_time'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:348:in `method_missing'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/config/environment.rb:194:in `create_table'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/config/../lib/../db/migrate/489_add_rule_tags.rb:27:in `up'
    org/jruby/RubyKernel.java:2223:in `send'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:282:in `migrate'
    jar:file:/E:/sonarqube/sonarqube-5.1.1/lib/server/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/1.8/benchmark.rb:293:in `measure'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:282:in `migrate'
    org/jruby/RubyKernel.java:2227:in `send'
    E:1:in `migrate'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:491:in `migrate'
    org/jruby/RubyProc.java:290:in `call'
    org/jruby/RubyProc.java:224:in `call'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:576:in `ddl_transaction'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:490:in `migrate'
    org/jruby/RubyArray.java:1613:in `each'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:477:in `migrate'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:401:in `up'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:383:in `migrate'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/config/../lib/database_version.rb:62:in `upgrade_and_start'
    E:/sonarqube/sonarqube-5.1.1/web/WEB-INF/app/models/database_migration_manager.rb:109:in `start_migration'
    org/jruby/RubyProc.java:290:in `call'
    org/jruby/RubyProc.java:228:in `call'

【问题讨论】:

  • 你说它不起作用,它给你什么错误?
  • 日志中有哪些错误?

标签: mysql sonarqube


【解决方案1】:

即使未定义 sonar.jdbc.url 设置,SonarQube 也会从默认数据库 H2 开始。 取消注释 MySQL 配置 (#sonar.jdbc.url=jdbc:mysql...) 并更新 url 是一件好事。

我可以确认您的 Sonarqube 服务器很好地使用 MySQL,因为我可以在日志中看到 ENGINE=InnoDB,这是 MySQL 特有的。

由于错误表明该表已经存在,也许您已经尝试在此架构上启动,但它未能结束,然后您重新尝试? 如果是这样,我鼓励您从新架构重新开始。

为了能够为您提供更多帮助,请发送完整的日志。

【讨论】:

  • 谢谢 我检查了数据库,发现有些表已经存在。我只是把它们扔掉了
猜你喜欢
  • 2012-09-03
  • 2017-12-26
  • 2012-09-16
  • 2018-02-05
  • 2015-07-09
  • 1970-01-01
  • 1970-01-01
  • 2011-07-31
  • 2014-02-18
相关资源
最近更新 更多