?i»?

Your IP : 18.225.156.236


Current Path : /home/scgforma/www/cloud/core/doc/admin/configuration_database/
Upload File :
Current File : /home/scgforma/www/cloud/core/doc/admin/configuration_database/linux_database_configuration.html

<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Database configuration &mdash; Nextcloud 13 Administration Manual 13 documentation</title>
    
    <link rel="stylesheet" href="../_static/" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/main.min.css" type="text/css" />
    <link rel="stylesheet" href="../_static/styles.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '13',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="../_static/js/jquery-fix.js"></script>
    <script type="text/javascript" src="../_static/bootstrap-3.1.0/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../_static/bootstrap-sphinx.js"></script>
    <link rel="top" title="Nextcloud 13 Administration Manual 13 documentation" href="../contents.html" />
    <link rel="up" title="Database configuration" href="index.html" />
    <link rel="next" title="Enabling MySQL 4-byte support" href="mysql_4byte_support.html" />
    <link rel="prev" title="Converting database type" href="db_conversion.html" />
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="theme-color" content="#1d2d44">

  </head>
  <body role="document">


<div class="wrap container not-front">
  <div class="content row">
  <main class="main">
    
			<div class="row">
				<div class="col-md-3">
					<div class="sidebar">
            <h1>Nextcloud 13 Administration Manual</h1>
            
            <div class="sidebar-search">
              <form class="headersearch" action="../search.html" method="get">
                <input type="text" value="" name="q" id="q" class="form-control" /> 
                <button  class="btn btn-default" type="submit" id="searchsubmit">Search</button>
              </form>
            </div>
            
							<div class="menu-support-container">
								<ul id="menu-support" class="menu">
									<ul>
                    <li><a href="../contents.html">Table of Contents</a></li>
									</ul>
                  <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../release_notes.html">Release notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_server/index.html">Server configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_user/index.html">User management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_files/index.html">File sharing and management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../file_workflows/index.html">File workflows</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Database configuration</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="db_conversion.html">Converting database type</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="">Database configuration</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#requirements">Requirements</a></li>
<li class="toctree-l3"><a class="reference internal" href="#parameters">Parameters</a></li>
<li class="toctree-l3"><a class="reference internal" href="#troubleshooting">Troubleshooting</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="mysql_4byte_support.html">Enabling MySQL 4-byte support</a></li>
<li class="toctree-l2"><a class="reference internal" href="bigint_identifiers.html">BigInt (64bit) identifiers</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_mimetypes/index.html">Mimetypes management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../maintenance/index.html">Maintenance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../issues/index.html">Issues and troubleshooting</a></li>
</ul>

								</ul>
							</div>
					</div>
				</div>
        

				<div class="col-md-9">
					<div class="page-content">
            
<ul class="prevnext-title list-unstyled list-inline">
  <li class="prev">
    <a href="db_conversion.html" title="Previous Chapter: Converting database type"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm">&laquo; Converting database type</span>
    </a>
  </li>
  <li class="next">
    <a href="mysql_4byte_support.html" title="Next Chapter: Enabling MySQL 4-byte support"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm">Enabling MySQL 4-byte support &raquo;</span>
    </a>
  </li>
</ul>
						
  <div class="section" id="database-configuration">
<h1>Database configuration<a class="headerlink" href="#database-configuration" title="Permalink to this headline">¶</a></h1>
<p>Nextcloud requires a database in which administrative data is stored. The following databases are currently supported:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.mysql.com/">MySQL</a> / <a class="reference external" href="https://mariadb.org/">MariaDB</a></li>
<li><a class="reference external" href="http://www.postgresql.org/">PostgreSQL</a></li>
<li><a class="reference external" href="http://www.oracle.com/">Oracle</a></li>
</ul>
<p>The MySQL or MariaDB databases are the recommended database engines.</p>
<div class="section" id="requirements">
<h2>Requirements<a class="headerlink" href="#requirements" title="Permalink to this headline">¶</a></h2>
<p>Choosing to use MySQL / MariaDB, PostgreSQL, or Oracle as your database
requires that you install and set up the server software first.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The steps for configuring a third party database are beyond the
scope of this document.  Please refer to the documentation for your specific
database choice for instructions.</p>
</div>
<div class="section" id="database-read-committed-transaction-isolation-level">
<span id="db-transaction-label"></span><h3>Database &#8220;READ COMMITTED&#8221; transaction isolation level<a class="headerlink" href="#database-read-committed-transaction-isolation-level" title="Permalink to this headline">¶</a></h3>
<p>As discussed above Nextcloud is using the <code class="docutils literal"><span class="pre">TRANSACTION_READ_COMMITTED</span></code> transaction isolation
level. Some database configurations are enforcing other transaction isolation levels. To avoid
data loss under high load scenarios (e.g. by using the sync client with many clients/users and
many parallel operations) you need to configure the transaction isolation level accordingly.
Please refer to the <a class="reference external" href="https://dev.mysql.com/doc/refman/5.7/en/set-transaction.html">MySQL manual</a>
for detailed information.</p>
</div>
</div>
<div class="section" id="parameters">
<h2>Parameters<a class="headerlink" href="#parameters" title="Permalink to this headline">¶</a></h2>
<p>For setting up Nextcloud to use any database, use the instructions in <a class="reference internal" href="../installation/installation_wizard.html"><em>Installation wizard</em></a>. You should not have to edit the respective values in the <code class="file docutils literal"><span class="pre">config/config.php</span></code>.  However, in special cases (for example, if you want to connect your Nextcloud instance to a database created by a previous installation of Nextcloud), some modification might be required.</p>
<div class="section" id="configuring-a-mysql-or-mariadb-database">
<h3>Configuring a MySQL or MariaDB database<a class="headerlink" href="#configuring-a-mysql-or-mariadb-database" title="Permalink to this headline">¶</a></h3>
<p>If you decide to use a MySQL or MariaDB database, ensure the following:</p>
<ul class="simple">
<li>That you have installed and enabled the pdo_mysql extension in PHP</li>
<li>That the <strong>mysql.default_socket</strong> points to the correct socket (if the database runs on the same server as Nextcloud).</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">MariaDB is backwards compatible with MySQL.  All instructions work for both. You will not need to replace mysql with anything.</p>
</div>
<p>The PHP configuration in <code class="file docutils literal"><span class="pre">/etc/php7/conf.d/mysql.ini</span></code> could look like this:</p>
<div class="highlight-python"><div class="highlight"><pre># configuration for PHP MySQL module
extension=pdo_mysql.so

[mysql]
mysql.allow_local_infile=On
mysql.allow_persistent=On
mysql.cache_size=2000
mysql.max_persistent=-1
mysql.max_links=-1
mysql.default_port=
mysql.default_socket=/var/lib/mysql/mysql.sock  # Debian squeeze: /var/run/mysqld/mysqld.sock
mysql.default_host=
mysql.default_user=
mysql.default_password=
mysql.connect_timeout=60
mysql.trace_mode=Off
</pre></div>
</div>
<p>Now you need to create a database user and the database itself by using the
MySQL command line interface. The database tables will be created by Nextcloud
when you login for the first time.</p>
<p>To start the MySQL command line mode use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">mysql</span> <span class="o">-</span><span class="n">uroot</span> <span class="o">-</span><span class="n">p</span>
</pre></div>
</div>
<p>Then a <strong>mysql&gt;</strong> or <strong>MariaDB [root]&gt;</strong> prompt will appear. Now enter the following lines and confirm them with the enter key:</p>
<div class="highlight-python"><div class="highlight"><pre>CREATE USER &#39;username&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;password&#39;;
CREATE DATABASE IF NOT EXISTS nextcloud;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON nextcloud.* TO &#39;username&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;password&#39;;
</pre></div>
</div>
<p>You can quit the prompt by entering:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">quit</span>
</pre></div>
</div>
<p>An Nextcloud instance configured with MySQL would contain the hostname on which
the database is running, a valid username and password to access it, and the
name of the database. The <code class="file docutils literal"><span class="pre">config/config.php</span></code> as created by the
<a class="reference internal" href="../installation/installation_wizard.html"><em>Installation wizard</em></a> would therefore contain entries like
this:</p>
<div class="highlight-python"><div class="highlight"><pre>&lt;?php

  &quot;dbtype&quot;        =&gt; &quot;mysql&quot;,
  &quot;dbname&quot;        =&gt; &quot;nextcloud&quot;,
  &quot;dbuser&quot;        =&gt; &quot;username&quot;,
  &quot;dbpassword&quot;    =&gt; &quot;password&quot;,
  &quot;dbhost&quot;        =&gt; &quot;localhost&quot;,
  &quot;dbtableprefix&quot; =&gt; &quot;oc_&quot;,
</pre></div>
</div>
</div>
<div class="section" id="postgresql-database">
<h3>PostgreSQL database<a class="headerlink" href="#postgresql-database" title="Permalink to this headline">¶</a></h3>
<p>If you decide to use a PostgreSQL database make sure that you have installed
and enabled the PostgreSQL extension in PHP. The PHP configuration in <code class="file docutils literal"><span class="pre">/etc/php7/conf.d/pgsql.ini</span></code> could look
like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c1"># configuration for PHP PostgreSQL module</span>
<span class="n">extension</span><span class="o">=</span><span class="n">pdo_pgsql</span><span class="o">.</span><span class="n">so</span>
<span class="n">extension</span><span class="o">=</span><span class="n">pgsql</span><span class="o">.</span><span class="n">so</span>

<span class="p">[</span><span class="n">PostgresSQL</span><span class="p">]</span>
<span class="n">pgsql</span><span class="o">.</span><span class="n">allow_persistent</span> <span class="o">=</span> <span class="n">On</span>
<span class="n">pgsql</span><span class="o">.</span><span class="n">auto_reset_persistent</span> <span class="o">=</span> <span class="n">Off</span>
<span class="n">pgsql</span><span class="o">.</span><span class="n">max_persistent</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
<span class="n">pgsql</span><span class="o">.</span><span class="n">max_links</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
<span class="n">pgsql</span><span class="o">.</span><span class="n">ignore_notice</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">pgsql</span><span class="o">.</span><span class="n">log_notice</span> <span class="o">=</span> <span class="mi">0</span>
</pre></div>
</div>
<p>The default configuration for PostgreSQL (at least in Ubuntu 14.04) is to use the peer authentication method. Check <code class="file docutils literal"><span class="pre">/etc/postgresql/9.3/main/pg_hba.conf</span></code> to find out which authentication method is used in your setup.
To start the postgres command line mode use:</p>
<div class="highlight-python"><div class="highlight"><pre>sudo -u postgres psql -d template1
</pre></div>
</div>
<p>Then a <strong>template1=#</strong> prompt will appear. Now enter the following lines and confirm them with the enter key:</p>
<div class="highlight-python"><div class="highlight"><pre>CREATE USER username CREATEDB;
CREATE DATABASE nextcloud OWNER username;
</pre></div>
</div>
<p>You can quit the prompt by entering:</p>
<div class="highlight-python"><div class="highlight"><pre>\q
</pre></div>
</div>
<p>An Nextcloud instance configured with PostgreSQL would contain the path to the socket on
which the database is running as the hostname, the system username the PHP process is using,
and an empty password to access it, and the name of the database. The <code class="file docutils literal"><span class="pre">config/config.php</span></code> as
created by the <a class="reference internal" href="../installation/installation_wizard.html"><em>Installation wizard</em></a> would therefore contain entries like
this:</p>
<div class="highlight-python"><div class="highlight"><pre>&lt;?php

  &quot;dbtype&quot;        =&gt; &quot;pgsql&quot;,
  &quot;dbname&quot;        =&gt; &quot;nextcloud&quot;,
  &quot;dbuser&quot;        =&gt; &quot;username&quot;,
  &quot;dbpassword&quot;    =&gt; &quot;&quot;,
  &quot;dbhost&quot;        =&gt; &quot;/var/run/postgresql&quot;,
  &quot;dbtableprefix&quot; =&gt; &quot;oc_&quot;,
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The host actually points to the socket that is used to connect to the database. Using localhost here will not work if postgreSQL is configured to use peer authentication. Also note, that no password is specified, because this authentication method doesn&#8217;t use a password.</p>
</div>
<p>If you use another authentication method (not peer), you&#8217;ll need to use the following steps to get the database setup:
Now you need to create a database user and the database itself by using the
PostgreSQL command line interface. The database tables will be created by
Nextcloud when you login for the first time.</p>
<p>To start the postgres command line mode use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">psql</span> <span class="o">-</span><span class="n">hlocalhost</span> <span class="o">-</span><span class="n">Upostgres</span>
</pre></div>
</div>
<p>Then a <strong>postgres=#</strong> prompt will appear. Now enter the following lines and confirm them with the enter key:</p>
<div class="highlight-python"><div class="highlight"><pre>CREATE USER username WITH PASSWORD &#39;password&#39;;
CREATE DATABASE nextcloud TEMPLATE template0 ENCODING &#39;UNICODE&#39;;
ALTER DATABASE nextcloud OWNER TO username;
GRANT ALL PRIVILEGES ON DATABASE nextcloud TO username;
</pre></div>
</div>
<p>You can quit the prompt by entering:</p>
<div class="highlight-python"><div class="highlight"><pre>\q
</pre></div>
</div>
<p>An Nextcloud instance configured with PostgreSQL would contain the hostname on
which the database is running, a valid username and password to access it, and
the name of the database. The <code class="file docutils literal"><span class="pre">config/config.php</span></code> as created by the
<a class="reference internal" href="../installation/installation_wizard.html"><em>Installation wizard</em></a> would therefore contain entries like
this:</p>
<div class="highlight-python"><div class="highlight"><pre>&lt;?php

  &quot;dbtype&quot;        =&gt; &quot;pgsql&quot;,
  &quot;dbname&quot;        =&gt; &quot;nextcloud&quot;,
  &quot;dbuser&quot;        =&gt; &quot;username&quot;,
  &quot;dbpassword&quot;    =&gt; &quot;password&quot;,
  &quot;dbhost&quot;        =&gt; &quot;localhost&quot;,
  &quot;dbtableprefix&quot; =&gt; &quot;oc_&quot;,
</pre></div>
</div>
</div>
</div>
<div class="section" id="troubleshooting">
<span id="db-troubleshooting-label"></span><h2>Troubleshooting<a class="headerlink" href="#troubleshooting" title="Permalink to this headline">¶</a></h2>
<div class="section" id="how-to-workaround-general-error-2006-mysql-server-has-gone-away">
<h3>How to workaround general error: 2006 MySQL server has gone away<a class="headerlink" href="#how-to-workaround-general-error-2006-mysql-server-has-gone-away" title="Permalink to this headline">¶</a></h3>
<p>The database request takes too long and therefore the MySQL server times out. Its
also possible that the server is dropping a packet that is too large. Please
refer to the manual of your database for how to raise the configuration options
<code class="docutils literal"><span class="pre">wait_timeout</span></code> and/or <code class="docutils literal"><span class="pre">max_allowed_packet</span></code>.</p>
<p>Some shared hosters are not allowing the access to these config options. For such
systems Nextcloud is providing a <code class="docutils literal"><span class="pre">dbdriveroptions</span></code> configuration option within your
<code class="file docutils literal"><span class="pre">config/config.php</span></code> where you can pass such options to the database driver.
Please refer to <a class="reference internal" href="../configuration_server/config_sample_php_parameters.html"><em>Config.php Parameters</em></a> for an example.</p>
</div>
<div class="section" id="how-can-i-find-out-if-my-mysql-postgresql-server-is-reachable">
<h3>How can I find out if my MySQL/PostgreSQL server is reachable?<a class="headerlink" href="#how-can-i-find-out-if-my-mysql-postgresql-server-is-reachable" title="Permalink to this headline">¶</a></h3>
<p>To check the server&#8217;s network availability, use the ping command on
the server&#8217;s host name (db.server.com in this example):</p>
<div class="highlight-python"><div class="highlight"><pre>ping db.server.dom
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre>PING db.server.dom (ip-address) 56(84) bytes of data.
64 bytes from your-server.local.lan (192.168.1.10): icmp_req=1 ttl=64 time=3.64 ms
64 bytes from your-server.local.lan (192.168.1.10): icmp_req=2 ttl=64 time=0.055 ms
64 bytes from your-server.local.lan (192.168.1.10): icmp_req=3 ttl=64 time=0.062 ms
</pre></div>
</div>
<p>For a more detailed check whether the access to the database server software
itself works correctly, see the next question.</p>
</div>
<div class="section" id="how-can-i-find-out-if-a-created-user-can-access-a-database">
<h3>How can I find out if a created user can access a database?<a class="headerlink" href="#how-can-i-find-out-if-a-created-user-can-access-a-database" title="Permalink to this headline">¶</a></h3>
<p>The easiest way to test if a database can be accessed is by starting the
command line interface:</p>
<p><strong>MySQL</strong>:</p>
<p>Assuming the database server is installed on the same system you&#8217;re running
the command from, use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">mysql</span> <span class="o">-</span><span class="n">uUSERNAME</span> <span class="o">-</span><span class="n">p</span>
</pre></div>
</div>
<p>To access a MySQL installation on a different machine, add the -h option with
the respective host name:</p>
<div class="highlight-python"><div class="highlight"><pre>mysql -uUSERNAME -p -h HOSTNAME
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre>mysql&gt; SHOW VARIABLES LIKE &quot;version&quot;;
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| version       | 5.1.67 |
+---------------+--------+
1 row in set (0.00 sec)
mysql&gt; quit
</pre></div>
</div>
<p><strong>PostgreSQL</strong>:</p>
<p>Assuming the database server is installed on the same system you&#8217;re running
the command from, use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">psql</span> <span class="o">-</span><span class="n">Uusername</span> <span class="o">-</span><span class="n">dnextcloud</span>
</pre></div>
</div>
<p>To access a MySQL installation on a different machine, add the -h option with
the respective host name:</p>
<div class="highlight-python"><div class="highlight"><pre>psql -Uusername -dnextcloud -h HOSTNAME
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre>postgres=# SELECT version();
PostgreSQL 8.4.12 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.1.3 20080704 (prerelease), 32-bit
(1 row)
postgres=# \q
</pre></div>
</div>
</div>
<div class="section" id="useful-sql-commands">
<h3>Useful SQL commands<a class="headerlink" href="#useful-sql-commands" title="Permalink to this headline">¶</a></h3>
<p><strong>Show Database Users</strong>:</p>
<div class="highlight-python"><div class="highlight"><pre>MySQL     : SELECT User,Host FROM mysql.user;
PostgreSQL: SELECT * FROM pg_user;
</pre></div>
</div>
<p><strong>Show available Databases</strong>:</p>
<div class="highlight-python"><div class="highlight"><pre>MySQL     : SHOW DATABASES;
PostgreSQL: \l
</pre></div>
</div>
<p><strong>Show Nextcloud Tables in Database</strong>:</p>
<div class="highlight-python"><div class="highlight"><pre>MySQL     : USE nextcloud; SHOW TABLES;
PostgreSQL: \c nextcloud; \d
</pre></div>
</div>
<p><strong>Quit Database</strong>:</p>
<div class="highlight-python"><div class="highlight"><pre>MySQL     : quit
PostgreSQL: \q
</pre></div>
</div>
</div>
</div>
</div>


            
<ul class="prevnext-title list-unstyled list-inline">
  <li class="prev">
    <a href="db_conversion.html" title="Previous Chapter: Converting database type"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm">&laquo; Converting database type</span>
    </a>
  </li>
  <li class="next">
    <a href="mysql_4byte_support.html" title="Next Chapter: Enabling MySQL 4-byte support"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm">Enabling MySQL 4-byte support &raquo;</span>
    </a>
  </li>
</ul>
					</div>
				</div>
			</div>
  </main>  
  </div>
</div>
  </body>
</html>