Skip to content

Instantly share code, notes, and snippets.

@hideojoho
Last active August 27, 2019 07:47
Show Gist options
  • Save hideojoho/818002cbc5182c9210f6d42441f2d49a to your computer and use it in GitHub Desktop.
Save hideojoho/818002cbc5182c9210f6d42441f2d49a to your computer and use it in GitHub Desktop.
How to use a new partition as MariaDB's data folder

How to use a new partition as MariaDB's data folder

Note

Changes from previous situations

  • You will remove mariadb and mariadb-server from the VM first
  • You will remove mariadb related files such as /etc/my.cnf and /var/lib/mysql
  • You will change the mounting point of a new partition to /var/lib/mysql
  • You will run mysql_secure_installation and the rest of commands again from How to set up a VM that has a local copy of Wikipedia

Let's begin

  • Remove mariadb and mariadb-server from VM
[vagrant@localhost ~]$ sudo systemctl stop mariadb
[vagrant@localhost ~]$ sudo yum remove mariadb mariadb-server
[vagrant@localhost ~]$ sudo rm /etc/my.cnf
[vagrant@localhost ~]$ sudo rm -rf /var/lib/mysql
  • Unmount the new partition and remount as /var/lib/mysql
[vagrant@localhost ~]$ sudo umount /dev/sda2
[vagrant@localhost ~]$ sudo vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Jun  1 17:13:31 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=8ac075e3-1124-4bb6-bef7-a6811bf8b870 /                       xfs     defaults        0 0
UUID=547a98b3-59a1-4748-90ac-fba19cd6524c /var/lib/mysql                xfs     defaults        0 0
/swapfile none swap defaults 0 0
[vagrant@localhost ~]$ sudo mkdir /var/lib/mysql
[vagrant@localhost ~]$ sudo mount -a
[vagrant@localhost ~]$ df -H
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        43G  7.5G   36G  18% /
devtmpfs        4.1G     0  4.1G   0% /dev
tmpfs           4.2G     0  4.2G   0% /dev/shm
tmpfs           4.2G  9.0M  4.1G   1% /run
tmpfs           4.2G     0  4.2G   0% /sys/fs/cgroup
tmpfs           821M     0  821M   0% /run/user/1000
/dev/sda2       226G   74M  226G   1% /var/lib/mysql

Now you have >200GB of space for MariaDB.

Install mariadb and mariadb-server and initiate the DB

[vagrant@localhost ~]$ sudo yum install -y mariadb mariadb-server
[vagrant@localhost ~]$ sudo systemctl enable mariadb
[vagrant@localhost ~]$ sudo systemctl start mariadb
[vagrant@localhost ~]$ sudo mysql_secure_installation

Then, follow the instruction from How to set up a VM that has a local copy of Wikipedia for the rest of the process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment