Prerequisites
- A Vultr server running up to date Arch Linux (see this article.)
- Sudo access:
- Commands required to be ran as root are prefixed by
#
, and ones that can be ran as a regular user by$
. The recommended way to run commands as root is to, as a regular user, prefix each of them withsudo
- Commands required to be ran as root are prefixed by
You can choose to install either MariaDB or MySQL, outlined in the following two sections.
Install MariaDB 10.3 Database
Install MariaDB:
# pacman -S mariadb
If you run the Btrfs filesystem, you should consider disabling copy-on-write for the database directory for performance reasons:
# chattr +C /var/lib/mysql/
Configure MariaDB:
# mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Start MariaDB, and make it start after every boot:
# systemctl enable --now mariadb
Complete recommended security measures. At the beginning, press ENTER for the current root database password, set a new root password, and press ENTER to answer yes on all further prompts.
# mysql_secure_installation
Install MySQL 8.0 Database
Although MariaDB is strongly recommended, you can alternatively install MySQL from the Arch Linux User Repository (AUR). Understand that AUR packages are not officially supported, may be updated less frequently, and because they are not necessarily submitted by a vetted Trusted User, their PKGBUILD/ETC should be reviewed for any suspect code. That said, as of early 2019, the current AUR maintainer for mysql
is “Muflone”. Although not a vetted Trusted User who can publish to the official repositories, he has been a valuable contributor to Arch since 2011, maintains about 250 AUR packages (many of them popular) and has never done anything suspect.
To install MySQL, compile and install the AUR package mysql
. See Building Packages on Arch Linux (Including the AUR). MariaDB and MySQL have very similar post-install steps.
If you run the Btrfs filesystem, you should consider disabling copy-on-write for the database directory for performance reasons:
# chattr +C /var/lib/mysql/
Configure MySQL:
# mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Start MySQL, and make it start after every boot:
# systemctl enable --now mysqld
Complete recommended security measures. An automatically generated temporary root database password was shown by the previous command. Set a new root password. Respond with y
on all further yes/no prompts, and select 2
for “STRONG” password validation policy.
# mysql_secure_installation
Note you cannot have MariaDB and MySQL installed on the same system, as MariaDB is made to be a drop-in replacement and has files of the same name. Also, when compiling with less than 4GB total RAM (physical RAM + swap), you may encounter a memory exhausted error while compiling.
Test Connection
To connect to MariaDB or MySQL as the root database user, run the following:
$ mysql -u root -p
To quit:
MariaDB [(none)]> quit
Consider A Firewall
You may want to consider configuring a firewall. By default, MariaDB will listen on port 3306
, not only from localhost, but also from anywhere on your public IP address. By default, MariaDB will only approve incoming connections from localhost, but external attempts will still reach MariaDB and get an error: Host... is not allowed to connect to this MariaDB server
. Although MariaDB is considered quite secure, it’s more secure to have a firewall not even give external packets to the MariaDB server, unless absolutely necessary. Even if direct remote access is desired, using a firewall to block the traffic and using a VPN would be more secure.
Prepare for Upgrades
By default, pacman
will upgrade MariaDB when new versions are released to the official Arch repositories, when you upgrade your entire Arch system by running the following:
# pacman -Syu
It is recommended to configure pacman
to not automatically install upgrades to MariaDB. When an upgrade is released and you upgrade your entire Arch system, pacman
will let you know a new version is available. Edit /etc/pacman.conf
, and add the following:
IgnorePkg = mariadb*
It’s a good idea to backup your database before upgrading.
When pacman
shows you there is a MariaDB upgrade, force upgrading the packages:
# pacman -S mariadb mariadb-clients mariadb-libs
If you’re running the AUR MySQL package, pacman
never automatically compiles and installs new versions from the AUR, so the above steps are unnecessary, but the ones below are still required.
After an upgrade, the package’s .install
script will alert you to perform the following steps, but blocking the automatic upgrade ensures you won’t miss it.
Restart MariaDB, to load the new version:
# systemctl restart mariadb
Check and update your tables to conform with the new version:
# mysql_upgrade -u root -p
Want to contribute?
You could earn up to $300 by adding new articles
Suggest an update
Request an article