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 3f4096d985319ba8f81396b2f6d6b617259f8d32..7d8c69ea0da5ab4586df5b178802eefa874e04e1 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 >}}