From 8422d79b61abce4faae6b0ea31ce91f9572249b4 Mon Sep 17 00:00:00 2001
From: Adam Caprez <acaprez2@unl.edu>
Date: Sat, 1 May 2021 01:54:03 +0000
Subject: [PATCH] Add instructions on using a volume with mysql.

---
 ...{connecting_to_mysql.md => using_mysql.md} | 57 ++++++++++++++++++-
 1 file changed, 55 insertions(+), 2 deletions(-)
 rename content/anvil/{connecting_to_mysql.md => using_mysql.md} (68%)

diff --git a/content/anvil/connecting_to_mysql.md b/content/anvil/using_mysql.md
similarity index 68%
rename from content/anvil/connecting_to_mysql.md
rename to content/anvil/using_mysql.md
index 3f4096d9..7d8c69ea 100644
--- a/content/anvil/connecting_to_mysql.md
+++ b/content/anvil/using_mysql.md
@@ -1,6 +1,6 @@
 +++
-title = "Connecting to MySQL instances"
-description = "How to connect to MySQL-based instances"
+title = "Using MySQL instances"
+description = "How to connect to and use MySQL-based instances"
 +++
 
 {{% notice info %}}
@@ -141,3 +141,56 @@ Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 mysql>
 {{< /highlight >}}
 
+### Using a volume to store the database
+
+By default, the database is stored on the instance's virtual disk. The amount of space
+available may not be sufficient for larger databases, so a _Volume_ may be used instead.
+
+All of the following setup commands need to be run as `root` in the instance after
+connecting via SSH from either [Windows]({{< relref "connecting_to_linux_instances_from_windows" >}})
+or [Mac]({{< relref "connecting_to_linux_instances_from_mac" >}}).
+
+{{% panel theme="danger" header="**Running commands as root**" %}}**Extreme care should be taken when running commands as `root.`** It is very easy to permanently delete data or cause irreparable damage to your instance.{{% /panel %}}
+
+In order to use a volume, first follow the instructions to
+[create and attach a volume]({{< relref "creating_and_attaching_a_volume" >}}) to your
+instance MySQL instance. Next, proceed with [formatting and mounting the volume]({{< relref "formatting_and_mounting_a_volume_in_linux" >}})
+in your instance. If all the steps complete without errors, you should have your volume mounted at `/mnt/myvolume`.
+
+Next, the MySQL server needs to be stopped and the existing contents of its storage directory copied to the volume:
+
+{{< highlight bash >}}
+service mysql stop
+rsync -av /var/lib/mysql/ /mnt/myvolume/
+{{< /highlight >}}
+
+Now the volume can be unmounted from `/mnt/myvolume` and remounted over the existing `/var/lib/mysql` location:
+
+{{< highlight bash >}}
+umount /mnt/myvolume
+mount /dev/vdb1 /var/lib/mysql
+{{< /highlight >}}
+
+Running the `df -h` command should show the `/var/lib/mysql` location as mounted from `/dev/vdb1` with the
+increased storage amount:
+
+{{< highlight bash >}}
+/dev/vdb1        99G  183M   94G   1% /var/lib/mysql
+{{< /highlight >}}
+
+In this example the volume size is 100GB. In general, it should be approximately the same size as your volume.
+
+Finally, restart the MySQL server:
+
+{{< highlight bash >}}
+service mysql start
+{{< /highlight >}}
+
+Assuming the `service` command doesn't return an error, the increased space is now available for use.
+
+The last step is to ensure the volume gets mounted automatically after the instance is rebooted.  To
+enable this, add the following line to the `/etc/fstab` file:
+
+{{< highlight bash >}}
+/dev/vdb1	/var/lib/mysql	ext4	defaults 0 0
+{{< /highlight >}}
-- 
GitLab