Using an External MySQL Database

After installing Shares, you can choose to use a MySQL database on a remote system rather than the default local MySQL database. You need to have the MySQL credentials, port, and the hostname of the remote machine.

Note: You must configure Shares to use an external MySQL database is you are sharing the MySQL database among multiple Shares instances.
  1. Dump the Shares and stats collector databases.

    Run the following commands:

    # mysqldump -u username -p web_production > sharesdb.sql
    # mysqldump -u username -p stats_collector > statscollectordb.sql

The following step takes place on the remote system hosting the remote MySQL server.

  1. Import the MySQL dumps into the MySQL on the remote system.

    First log in to the MySQL command-line client and create the two needed databases if they do not exist:

    mysql> create database web_production;
    mysql> create database stats_collector;

    Exit the MySQL client then import the dumps. You can do this with commands like the following:

    # mysql -u username -p web_production < sharesdb.sql
    # mysql -u username -p stats_collector < statscollectordb.sql

The following steps return to the system with Shares installed.

  1. Back on the system with Shares, update the Shares application configuration file, which can be found at the following location:
    C:\Shares\www\config\database.yml

    Add in the remote_host, remote_username, remote_password and port for your remote MySQL in the production and production_stats_collector sections:

    production:
    database: web_production    
    username: "remote_user"    
    password: "remote_password"    
    host: remote_host    
    port: remote_port    
    encoding: utf8    
    reconnect: false    
    pool: 5                
    
    production_stats_collector:    
    database: stats_collector    
    username: "remote_user"    
    password: "remote_password"
    host: remote_host    
    port: remote_port
    encoding: utf8    
    reconnect: false    
    pool: 5
  2. Update the stats collector configuration file, which can be found at the following location:
    C:\Shares\statscollector\etc\persistence.xml

    Add in the remote_host, remote_username and remote_password for the remote MySQL server under the connection URL header:

    <!-- connection URL: jdbc:mysql://HOST:PORT/DATABASE -->    
    <property name="hibernate.connection.url" value="jdbc:mysql://remote_host/stats_collector"/>    
    <property name="hibernate.connection.username" value="remote_user"/>    
    <property name="hibernate.connection.password" value="remote_password"/>
  3. Restart Shares services.
    Go to Start Menu > Control Panel > Administrative Tools > Services to start and stop any of the following services:
    • Aspera Nginx Service
    • Aspera Delayed Job Service
    • Aspera Web Services
    • Aspera Stats Collector
  4. If you are sharing the MySQL database with multiple Shares instances, make sure the following Shares files are identical on every Shares instance:
    C:\Shares\statscollector\etc\keystore.jks
    C:\Shares\statscollector\etc\persistence.xml
    C:\Shares\www\config\aspera\secret.rb
    C:\Shares\www\config\database.yml
    C:\Shares\www\config\initializers\secret_token.rb