Could not create connection to database server. (MySQL)

I’m trying to setup a new instance of HippoCMS with a MySQL database.

I’m getting the following error when attempting to run mvn -Pcargo.run;

[WARNING] [talledLocalContainer] 27-Nov-2018 12:38:39.409 WARNING [localhost-startStop-1] org.apache.catalina.core.NamingContextListener.addResource Failed to register in JMX: [javax.naming.NamingException: Unexpected exception resolving reference [Root exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)]]

Using Configure Hippo CMS for MySQL as a guide I’ve done the following;

  • Added the example JNDI resource to conf/context.xml after replacing DBUSER, DBPASS, DBHOST, DBPORT and DBNAME
  • Added the example repository.xml file to the conf directory
  • Created a database on a local instance of MySQL
  • Created a user with CREATE, ALTER, DROP, INDEX, SELECT, INSERT, UPDATE, DELETE and LOCK TABLES privileges

This is also for a development environment so using Use MySQL in a Development Environment I have;

  • Added the MySQL driver dependency to pom.xml. (I added the <dependencies> node alongside the <depenendencyManagement> node instead of inside it as mentioned in the warning in the instructions.)
  • Added the MySQL driver to the cargo.run profile in pom.xml
  • Added the repo.config to the <systemProperties> in the cargo.run profile

I’ve checked every page in the documentation that seems relevant but I’m not sure where I’m going wrong.

I’m happy to provide more specific information about any of the above but didn’t know which finer details would be important and which would just be clutter.

Thanks in advance.

Well the error is that is can’t connect to the database. Check to see that the database is running and accessible.

@jasper.floor Thanks for the reply

The database is running and accessible. I confirmed this by connecting to it via another application on a different machine.

Here’s my config from a project where this works for me.
Cargo.run profile:

<profile>
      <id>cargo.run</id>
      <properties>
        <!--Already defined in hippo-cms-project POM. Override here for project, if necessary-->
        <!--<repo.bootstrap>true</repo.bootstrap>-->
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <configuration>
              <configuration>
                <configfiles>
                  <configfile>
                    <file>${project.basedir}/conf/context.xml</file>
                    <todir>conf/</todir>
                    <tofile>context.xml</tofile>
                  </configfile>
                  <configfile>
                    <file>${project.basedir}/conf/catalina-logging.properties</file>
                    <todir>conf/</todir>
                    <tofile>logging.properties</tofile>
                  </configfile>
                </configfiles>
                <files>
                  <file>
                    <file>${project.basedir}/repository-data/development/target/myhippoproject-repository-data-development-${project.version}.jar</file>
                    <todir>${development-module-deploy-dir}</todir>
                  </file>
                </files>
              </configuration>
              <deployables>
                <deployable>
                  <type>war</type>
                  <properties>
                    <context>/cms</context>
                  </properties>
                  <location>${project.basedir}/cms/target/cms.war</location>
                </deployable>
                <deployable>
                  <location>${project.basedir}/site/target/site.war</location>
                  <type>war</type>
                  <properties>
                    <context>/site</context>
                  </properties>
                </deployable>
                <deployable>
                  <location>${project.basedir}/essentials/target/essentials.war</location>
                  <type>war</type>
                  <properties>
                    <context>/essentials</context>
                  </properties>
                </deployable>
              </deployables>
              <container>
                <dependencies>
                  <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <classpath>extra</classpath>
                  </dependency>
                </dependencies>
                <systemProperties>
                  <log4j.configurationFile>file://${project.basedir}/conf/log4j2-dev.xml</log4j.configurationFile>
                  <!-- enables auto export and web files watch: -->
                  <project.basedir>${project.basedir}</project.basedir>
                  <send.usage.statistics.to.hippo>true</send.usage.statistics.to.hippo>
                  <repo.config>file:${project.basedir}/conf/repository.xml</repo.config>
                  <org.apache.jackrabbit.core.cluster.node_id>${cluster.node}</org.apache.jackrabbit.core.cluster.node_id>
                </systemProperties>
              </container>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

conf/context.xml:
(I created a db called repositoryds)

  <Resource
    name="jdbc/repositoryDS" auth="Container" type="javax.sql.DataSource"
    maxTotal="100" maxIdle="10" initialSize="2" maxWaitMillis="10000"
    testWhileIdle="true" testOnBorrow="false" validationQuery="SELECT 1"
    timeBetweenEvictionRunsMillis="10000"
    minEvictableIdleTimeMillis="60000"
    username="hippo" password="hippo"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/repositoryDS?characterEncoding=utf8&amp;useSSL=false"/>-->

Hope this helps

Thanks for the reply @bcanvural

Your cargo.run profile and Resource declaration match my own. So, it’s still not connected, but at least I know I’ve not done anything wrong in either of those areas, thanks :slight_smile:

@bcanvural : I have created the conf/context.xml and cargo.run profile as you mention . But table is not created in MySQL database. I am not getting any error.

conf/context.xml:

<Resource
name="jdbc/repositoryDS" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="10" initialSize="2" maxWaitMillis="10000"
testWhileIdle="true" testOnBorrow="false" validationQuery="SELECT 1"
timeBetweenEvictionRunsMillis="10000"
minEvictableIdleTimeMillis="60000"
username="root" password="12345"
driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/hippodb?characterEncoding=utf8&amp;useSSL=false"/>

root pom.xml :

  <profile>
  <id>cargo.run</id>
  <properties>
    <!-- Already defined in the cms project POM. Override here for your project, if necessary -->
    <!-- <repo.bootstrap>true</repo.bootstrap> -->
  </properties>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <configuration>	
			
			<configuration>
			<container>
			  <systemProperties>
				<repo.config>file:${project.basedir}/conf/repository.xml</repo.config>
			  </systemProperties>
			</container>
		  </configuration>

          <configuration>
            <configfiles>
              <configfile>
                <file>${project.basedir}/conf/context.xml</file>
                <todir>conf/</todir>
                <tofile>context.xml</tofile>
              </configfile>
              <configfile>
                <file>${project.basedir}/conf/catalina-logging.properties</file>
                <todir>conf/</todir>
                <tofile>logging.properties</tofile>
              </configfile>
            </configfiles>
            <files>
              <file>
                <file>${project.basedir}/repository-data/development/target/hitech-repository-data-development-${project.version}.jar</file>
                <todir>${development-module-deploy-dir}</todir>
              </file>
              <file>
                <file>${project.basedir}/repository-data/site-development/target/hitech-repository-data-site-development-${project.version}.jar</file>
                <todir>${development-module-deploy-dir}</todir>
              </file>
            </files>
          </configuration>
          <deployables>
            <deployable>
              <type>war</type>
              <properties>
                <context>/cms</context>
              </properties>
              <location>${project.basedir}/cms/target/cms</location>
            </deployable>
            <deployable>
              <location>${project.basedir}/site/webapp/target/site</location>
              <type>war</type>
              <properties>
                <context>/site</context>
              </properties>
            </deployable>
            <deployable>
              <location>${project.basedir}/essentials/target/essentials</location>
              <type>war</type>
              <properties>
                <context>/essentials</context>
              </properties>
            </deployable>
          </deployables>
          <container>			  
			<dependencies>
              <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <classpath>extra</classpath>
              </dependency>
            </dependencies>				
            <systemProperties>
              <log4j.configurationFile>file://${project.basedir}/conf/log4j2-dev.xml</log4j.configurationFile>
              <!-- enables auto export and web files watch: -->
              <project.basedir>${project.basedir}</project.basedir>
              <send.usage.statistics.to.hippo>true</send.usage.statistics.to.hippo>
            </systemProperties>
          </container>				
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>

2 YEARS LATER… :sweat_smile:

delete any existing storage directories (repo.path)…are you running right maven profile?

Thanks @machak for quick response.

I am pretty new in Bloomreach and start exploring Bloomreach couple of days before. I have face the same issue that’s why I have replied here and not create a new thread. .

I am pretty new in Bloomreach. So could you please elaborate your answer. So that I can understand and follow the steps.

see: "** Repository Storage Directory Location** part at: