Gurult
Gurult

Reputation: 215

Sonar setup MYSQL

I am trying change default database to MYSQL. I used some tutorials like http://laurenthinoul.com/how-to-change-sonar-default-database/. Mysql database created and works.

My problem is that file in folder ..sonarqube\sonarqube-5.1.1\conf default file sonar.properties all configurations are commented i I tried uncomment mysql driver, but it doesnot work. My question why default database is commented, and how change to 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

Then I trying access localhost:9000/setup I got error

Migration failed: 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 . Please check logs.

LOG:

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'

Upvotes: 1

Views: 3260

Answers (1)

Julien L.
Julien L.

Reputation: 2587

SonarQube is starting with the default database H2 even if no sonar.jdbc.url settings is defined. Uncommenting the MySQL configuration (#sonar.jdbc.url=jdbc:mysql...) and updating the url is the good thing to do.

I can confirm that your Sonarqube server is well using MySQL as I can see ENGINE=InnoDB in the log, which is specific to MySQL.

As the errors saids that the table already exists, maybe you've already tried to start on this schema but it fails to end and then you've re-try ? If so, I encourage you to restart from a fresh schema.

And in order to be able to help you more, please send the whole logs.

Upvotes: 1

Related Questions