title: Steps to install MariaDB (MySQL) database files in NFS share, and run the service as a regular user (Linux)
body: <p>I've been looking for instructions but couldn't find a complete instruction set for the following:</p>
  
  <ol>
  <li>Install MariaDB (MySQL) database and logs in an NFS share</li>
  <li>Run MariaDB daemon as  a regular user defined in NIS</li>
  </ol>
  
  <p>Using:</p>
  
  <ul>
  <li>Linux Ubuntu 14.04</li>
  <li>MariaDB 10.2.5</li>
  </ul>
  
  <p>After reading many posts, and doing some trial &amp; error, I came up with the steps listed below.  <strong>I'd like to know if something is missing or wrong ??</strong></p>
  
  <p><strong>1- Create directory in NFS:</strong></p>
  
  <pre><code>mkdir /nfs_dir/data -p
  mkdir /nfs_dir/logs -p
  chmod 700 /nfs_dir/data
  chmod 750 /nfs_dir/logs
  chown nisuser:nisgroup ...
  </code></pre>
  
  <p><strong>2- Crate run dir in local drive:</strong></p>
  
  <pre><code>sudo mkdir /var/run/mariadb
  sudo chown nisuser:nisgroup /var/run/mariadb
  sudo chmod 755 /var/run/mariadb
  </code></pre>
  
  <p><strong>3- Install MariaDB</strong></p>
  
  <p>Instructions from download.mariadb.org</p>
  
  <p><strong>4- <code>sudo service mysql  stop</code></strong></p>
  
  <p><strong>5- Create database files in NFS:</strong>
      sudo mysql_install_db --user=nisuser --datadir/nfs_dir/data</p>
  
  <p><strong>6- Edit MariaDB config</strong> (below, only the edited lines are shown, others left as default):</p>
  
  <pre><code>sudo vi /etc/mysql/my.cnf
  
  [client]
  socket = /var/run/mariadb/m.sock
  
  [mysql_safe]
  socket = /var/run/mariadb/m.sock
  
  [mysqld]
  user = nisuser
  pid-file = /var/run/mariadb/m.pid
  socket  = /var/run/mariadb/m.sock
  datadir = /nfs_dir/data
  log_warnings = 1
  log_error = /nfs_dir/logs/error.log
  log_bin = /nfs_dir/logs/mysql-bin.log
  </code></pre>
  
  <p><strong>7 - Update the MySQL Init script</strong></p>
  
  <pre><code>sudo vi /etc/init.d/mysql
  </code></pre>
  
  <p>Replace the test line as follows:</p>
  
  <pre><code>test -e /var/run/mariadb || install -m 755 -o nisuser -g nisgroup -d /var/run/mariadb
  </code></pre>
  
  <p><strong>8 - Update Debian config file</strong></p>
  
  <pre><code>sudo /etc/mysql/debian.cnf
  
  [client]
  socket = /var/run/mariadb/m.sock
  
  [mysql_upgrade]
  socket = /var/run/mariadb/m.sock
  </code></pre>
  
  <p><strong>9- Create debian-sys-main user</strong> in mysql > user table</p>
  
  <pre><code>create user 'debian-sys-main'@'localhost' identified by 'password_from_debian_file'; GRANT ALL PRIVILEGES ON *.* to 'debian-sys-main'@'localhost' with GRANT OPTION;
  </code></pre>
  
  <p><strong>10 - Restart MariaDB</strong> </p>
  
  <pre><code>sudo service mysql restart
  </code></pre>