Answers.Body: <p>Jon has also answered the original question of <a href="https://civicrm.stackexchange.com/a/31146/233">how to install CiviCRM in its own database</a>.</p>
  
  <p>Specifically, if you add the connection information in your settings file (before installing CiviCRM), it uses that, i.e. in settings.php add in:</p>
  
  <p><code>
  $databases['civicrm']['default'] = [
    'database' => 'civicrm',
    'username' => 'mysqluser',
    'password' => 'a-mysql-password',
    'prefix' => '',
    'host' => 'localhost-or-whatever',
    'port' => '',
    'namespace' => 'Drupal\Core\Database\Driver\mysql',
    'driver' => 'mysql'
  ]</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-20T20:28:20.380Z
Answers.LastActivityDate: 2020-01-21T22:43:56.573Z
Answers.LastEditDate: 2020-01-21T22:43:56.573Z
Answers.UserDisplayName: Alan Dixon
Answers.Body: <p>I was able to separate my Drupal 8 database from my CiviCRM database fairly easily, here are my notes I took on how to do it. Note that these steps aren't particularly specific to Drupal 8, and can be used to convert any single-database install into a two-database install.</p>
  
  <ul>
  <li>Create a new database (e.g. "example_civi") on the same server.</li>
  <li>Do NOT create a separate MySQL user - just use the same MySQL user
  Drupal uses.</li>
  <li>Grant permissions to the user.  Here's the permissions you need:</li>
  </ul>
  
  <pre><code>TABLES, CREATE TEMPORARY TABLES, TRIGGER, CREATE ROUTINE, ALTER ROUTINE,
  CREATE VIEW, SHOW VIEW, REFERENCES ON ``.* TO ''@'localhost';
  </code></pre>
  
  <ul>
  <li><p>Load a dump that just has CiviCRM tables into the new database.  Steps to <a href="https://stackoverflow.com/questions/5268936/mysqldump-only-tables-with-certain-prefix-mysqldump-wildcards">dump tables by prefix</a> are available. Since you sound like you're potentially upgrading an existing site, you can just copy the existing database instead.</p></li>
  <li><p>Drop the CiviCRM tables from the Drupal database.  There's a good
  explanation of how to <a href="https://stackoverflow.com/a/1589324/2832108">remove tables by prefix</a>.</p></li>
  </ul>
  
  <p>On the last step, note that foreign key constraints will cause some tables not to delete.  You'll either need to run those steps multiple times or disable FK constraints before dropping the tables.</p>
  
  <p>UPDATE:  See also how to enable <a href="https://civicrm.stackexchange.com/a/31146/12">Views integration on D8 with separated databases</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-21T22:04:51.933Z
Answers.Text: Thank you Jon for this share of experience, so you recommend to create first the mixed database (D8 + Civi), then adapt the civicrm.settings.php to reach an external Civi database.   I feel the way just tried is quite similar except that I add the civicrm.settings.php before the civicrm activation. So I will try again following your order and come bak to give the result.
Answers.UserDisplayName: Ichi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-22T10:54:33.877Z
Answers.Text: Hello Jon, I struggle too much to even set Civi w/ D8. May I ask you what is the method that you chose for the initial set of Civi w/ D8 ? In this page there is several methods w/ different version of Civi https://colorfield.be/blog/install-civicrm-5-with-drupal-8-using-lando - There is the method provided by David Snopek with the latest CiviCRM 5.6.0 or the another Drupal 8 CiviCRM module from GitHub that is currently verified to work against Drupal 8.0.5 and CiviCRM 4.7.3. I struggle w/ both method. My CiviCRM is 5.6.0.
Answers.UserDisplayName: Ichi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-22T20:12:51.260Z
Answers.Text: Yes, I create the mixed database first.  I can't comment on whether separating them in `civicrm.settings.php` before install is effective - but I assume not, since the installer typically creates `civicrm.settings.php`.  I use the David Snopek "full manual process" from [his D8/Civi install instructions](https://www.mydropwizard.com/blog/how-install-civicrm-drupal-8-and-why-choose-it-over-pure-drupal-crm).
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-27T12:24:29.433Z
Answers.Text: Thank you Jon,
  Following your advice, I kept trying to set Civi on Drupal8. After many tests I could successfully used the "full manual process" of David Snopek with the latest versions of Drupal and Civicrm : - Drupal 8.6.4 - CiviCRM 5.8.2 There is now new issues that arise with the CiviCRM extensions.
Answers.UserDisplayName: Ichi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-21T21:33:55.683Z
Answers.LastActivityDate: 2019-06-21T13:51:35.103Z
Answers.LastEditDate: 2019-06-21T13:51:35.103Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I am very confused with the evolution of Drupal 8 going away from its ability in Drupal 7 to easily handle multisite.</p>
  
  <p>Is it still possible to share a Civi database with the multisite extension with several Drupal 8 sites? </p>
  
  <p>What about sharing a CiviCRM database between a mix of Drupal 7 and Drupal 8 sites?</p>
  
  <p>More globally, can a Civi database be separated from the Drupal 8 database ?</p>
  
  <p>=========
  I had read from David Snopek while researching this question that he thought it might work to use an edited version of the file civicrm.settings.php, though hadn't actually tried because of his server policies.</p>
  
  <p>So I tried integrating an additional Drupal 8 site already running with a Drupal 7 site! I edited the civicrm.settings.php in Drupal 7 site in order to adapt it to the path of the Drupal 8 site as follows:</p>
  
  <pre><code>$civicrm_root = '/PATH/SITE/public_html/sites/all/modules/civicrm';
  </code></pre>
  
  <p>became this :</p>
  
  <pre><code>$civicrm_root = '/PATH/SITE/public_html/vendor/civicrm/civicrm-core';
  </code></pre>
  
  <p>But I this error message was the result:</p>
  
  <pre><code>PHP Fatal error:  Call to undefined function variable_get() in /var/data/sites/reveal/public_html/vendor/civicrm/civicrm-core/CRM/Utils/System/Drupal.php on line 790and –-
  </code></pre>
  
Tags: <drupal-8><drupal-multi-site>
Title: How to install a separated Civi database with Drupal 8?
ThreadText: # How to install a separated Civi database with Drupal 8?
  
  (Asked by: username_0 on 2018-10-21)
  
  I am very confused with the evolution of Drupal 8 going away from its ability in Drupal 7 to easily handle multisite.
  
  Is it still possible to share a Civi database with the multisite extension with several Drupal 8 sites?
  
  What about sharing a CiviCRM database between a mix of Drupal 7 and Drupal 8 sites?
  
  More globally, can a Civi database be separated from the Drupal 8 database ?
  
  =========
  I had read from David Snopek while researching this question that he thought it might work to use an edited version of the file civicrm.settings.php, though hadn't actually tried because of his server policies.
  
  So I tried integrating an additional Drupal 8 site already running with a Drupal 7 site! I edited the civicrm.settings.php in Drupal 7 site in order to adapt it to the path of the Drupal 8 site as follows:
  
  ```
  $civicrm_root = '/PATH/SITE/public_html/sites/all/modules/civicrm';
  
  ```
  
  became this :
  
  ```
  $civicrm_root = '/PATH/SITE/public_html/vendor/civicrm/civicrm-core';
  
  ```
  
  But I this error message was the result:
  
  ```
  PHP Fatal error:  Call to undefined function variable_get() in /var/data/sites/reveal/public_html/vendor/civicrm/civicrm-core/CRM/Utils/System/Drupal.php on line 790and –-
  
  ```
  
  **Tags:** drupal-8, drupal-multi-site
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-10-21. Score: 7 | Accepted answer
  
  I was able to separate my Drupal 8 database from my CiviCRM database fairly easily, here are my notes I took on how to do it. Note that these steps aren't particularly specific to Drupal 8, and can be used to convert any single-database install into a two-database install.
  
  * Create a new database (e.g. "example\_civi") on the same server.
  * Do NOT create a separate MySQL user - just use the same MySQL user
    Drupal uses.
  * Grant permissions to the user. Here's the permissions you need:
  
  ```
  TABLES, CREATE TEMPORARY TABLES, TRIGGER, CREATE ROUTINE, ALTER ROUTINE,
  CREATE VIEW, SHOW VIEW, REFERENCES ON ``.* TO ''@'localhost';
  
  ```
  
  * Load a dump that just has CiviCRM tables into the new database. Steps to [dump tables by prefix](https://stackoverflow.com/questions/5268936/mysqldump-only-tables-with-certain-prefix-mysqldump-wildcards) are available. Since you sound like you're potentially upgrading an existing site, you can just copy the existing database instead.
  * Drop the CiviCRM tables from the Drupal database. There's a good
    explanation of how to [remove tables by prefix](https://stackoverflow.com/a/1589324/2832108).
  
  On the last step, note that foreign key constraints will cause some tables not to delete. You'll either need to run those steps multiple times or disable FK constraints before dropping the tables.
  
  UPDATE: See also how to enable [Views integration on D8 with separated databases](https://civicrm.stackexchange.com/a/31146/12).
  
  > **Comments:**
  > **username_0**: Thank you Jon for this share of experience, so you recommend to create first the mixed database (D8 + Civi), then adapt the civicrm.settings.php to reach an external Civi database.   I feel the way just tried is quite similar except that I add the civicrm.settings.php before the civicrm activation. So I will try again following your order and come bak to give the result.  
  > **username_0**: Hello Jon, I struggle too much to even set Civi w/ D8. May I ask you what is the method that you chose for the initial set of Civi w/ D8 ? In this page there is several methods w/ different version of Civi https://colorfield.be/blog/install-civicrm-5-with-drupal-8-using-lando - There is the method provided by David Snopek with the latest CiviCRM 5.6.0 or the another Drupal 8 CiviCRM module from GitHub that is currently verified to work against Drupal 8.0.5 and CiviCRM 4.7.3. I struggle w/ both method. My CiviCRM is 5.6.0.  
  > **username_2**: Yes, I create the mixed database first.  I can't comment on whether separating them in `civicrm.settings.php` before install is effective - but I assume not, since the installer typically creates `civicrm.settings.php`.  I use the David Snopek "full manual process" from [his D8/Civi install instructions](https://www.mydropwizard.com/blog/how-install-civicrm-drupal-8-and-why-choose-it-over-pure-drupal-crm).  
  > **username_0**: Thank you Jon, Following your advice, I kept trying to set Civi on Drupal8. After many tests I could successfully used the "full manual process" of David Snopek with the latest versions of Drupal and Civicrm : - Drupal 8.6.4 - CiviCRM 5.8.2 There is now new issues that arise with the CiviCRM extensions.  
  
  ---
  
  ### Answer by username_1 on 2020-01-20. Score: 3
  
  Jon has also answered the original question of [how to install CiviCRM in its own database](https://civicrm.stackexchange.com/a/31146/233).
  
  Specifically, if you add the connection information in your settings file (before installing CiviCRM), it uses that, i.e. in settings.php add in:
  
  `$databases['civicrm']['default'] = [
  'database' => 'civicrm',
  'username' => 'mysqluser',
  'password' => 'a-mysql-password',
  'prefix' => '',
  'host' => 'localhost-or-whatever',
  'port' => '',
  'namespace' => 'Drupal\Core\Database\Driver\mysql',
  'driver' => 'mysql'
  ]`
  
  
  ---
  
  