MySQL is an open-source relational database management system (RDBMS) that’s popular for its performance, ease of use, and extensive ecosystem. Archil makes it simple to run MySQL directly on Amazon S3, so you don’t have to worry about running out of capacity or paying for unused storage.

Create an Archil disk

First, follow the Archil Getting Started Guide to create an Archil disk that you want to use as the backing storage for your MySQL database.

Install MySQL

The exact instructions for installing MySQL will vary depending on your operating system. For example, on Amazon Linux 2023, you can install MySQL with the following commands:
# Download the MySQL community Yum repository
sudo wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
sudo dnf install -y mysql80-community-release-el9-1.noarch.rpm

# Import the MySQL GPG key
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

# Install MySQL
sudo dnf install -y mysql-community-server mysql-community-client
Mount your Archil disk to an easy to access directory.
# Mount Archil disk
sudo mkdir -p /mnt/archil
sudo archil mount dsk-DISKID /mnt/archil --region aws-us-east-1 --auth-token TOKEN

# Create the directory for MySQL data
sudo mkdir -p /mnt/archil/mysql
sudo chown -R mysql:mysql /mnt/archil/mysql
Set the MySQL data directory to the Archil disk. Open the file /etc/my.cnf in your favorite editor. Under the [mysqld] section, identify the line that starts with datadir= and edit the path to look like the following:
datadir=/mnt/archil/mysql
Initialize the MySQL database in our data directory, and start the MySQL service.
sudo mysqld --initialize --user=mysql --datadir=/mnt/archil/mysql
sudo systemctl start mysqld
Note the temporary password that was generated for the root user by looking through the initialization log.
sudo grep 'temporary password' /var/log/mysqld.log
Change your root password to something more secure.
mysql --connect-expired-password -u root -p -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOUR_NEW_PASSWORD';"
By default, the MySQL password policy requires that you set a password of at least 8 characters that contains at least one uppercase letter, one lowercase letter, one number, and one special character.
Validate that MySQL is running on Archil by executing the following command, logging in with your new password.
mysql -u root -p -e "SELECT @@datadir;"
This should output the data directory that we previously set up, /mnt/archil/mysql.

(Optional) Run a benchmark to validate performance

First, we will download and compile the sysbench tool.
# Install development dependencies for sysbench
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y mysql-devel openssl-devel glibc-static libstdc++-static

# Download and compile sysbench
git clone https://github.com/akopytov/sysbench.git
cd sysbench
./autogen.sh
./configure
make -j
sudo make install
Let’s create a database and write test data to it.
mysql -u root -p -e "CREATE DATABASE sbtest;"

sysbench /usr/local/share/sysbench/oltp_read_write.lua \
  --mysql-host=127.0.0.1 \
  --mysql-user=root \
  --mysql-password='YourPassword' \
  --mysql-db=sbtest \
  --tables=4 --table-size=100000 prepare
Finally, run the test:
# Run the sysbench test
sysbench /usr/local/share/sysbench/oltp_read_write.lua \
  --mysql-host=127.0.0.1 \
  --mysql-user=root \
  --mysql-password='YourPassword' \
  --mysql-db=sbtest \
  --threads=4 --time=30 run

# Cleanup the sysbench test
sysbench /usr/local/share/sysbench/oltp_read_write.lua \
  --mysql-host=127.0.0.1 \
  --mysql-user=root \
  --mysql-password='YourPassword' \
  --mysql-db=sbtest cleanup