You can choose to install either MariaDB or MySQL, outlined in the following two sections.
# 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/
# 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.
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. MariaDB and MySQL have very similar post-install steps.
# 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.
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.
To connect to MariaDB or MySQL as the root database user, run the following:
$ mysql -u root -p
MariaDB [(none)]> quit
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.
Host... is not allowed to connect to this MariaDB server
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
Powered by BetterDocs