MariaDB
MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. It is notable for being led by the original developers of MySQL, who forked it due to concerns over its acquisition by Oracle.
This is the general documentation for normal and common general usage, for professional usage please use Production DataBases : mysql that is the same as MariaDB but with several modifications focused on production and security!
Installation
Alpine Linux has dummy counterparts packages for those that are not close to that change from mysql to mariadb naming packages.
Take in consideration that the user mysql
was created during instalation of packages, in the initialization section two users will be created in database init: root
and mysql
, and in that point only if are in their respective system accounts, will be able to connect to the database service.
apk add mysql mysql-client
That will install the most used ones.. mariadb-cient
and mariadb-server
, rest of packages are brief described here for more information, here are listed in orden of relevance for production server
MySQL name package | Since Alpine: | Brief usage | Related package |
---|---|---|---|
mysql | v2 | it's a dummy package to easy install of mariadb | mariadb |
mysql-client | v2 | it's a dummy package to easy install of commands tools | mariadb-client |
mariadb | v2 | server equivalent to mysql-server | mariadb-common |
mariadb-client | v2 | connection command line and tools | mariadb-common |
mariadb-doc | v3.0 | manpages are there! | man man-pages |
mariadb-connector-odbc | edge | coding or making OS level connections, to any DB without libs install | . |
mariadb-connector-c | v3.8 | coding connection on C sources | mariadb-connector-c-dev |
mariadb-backup | v3.8 | to external backup devices, not widely used, in past was inside mariadb package | . |
mariadb-server-utils | v3.8 | server commands not widely used, in past was inside mariadb package | . |
mariadb-dev | v3.1 | Need for compilations depends on source code | . |
mariadb-test | v3.3 | testing suite from MariaDB tools | . |
mariadb-mytop | v3.9 | data performance monitoring | . |
mariadb-plugin-rocksdb | v3.9 | plain key-value event relational for data | . |
mariadb-static | v3.8 | static libs for static non depends linking in builds | . |
mariadb-embedded | v3.9 | the libmysqld identical interface as the C client | mariadb-embedded-dev |
mariadb-embedded-dev | v3.9 | use the normal mysql.h and link with libmysqld instead of libmysqlclient | mariadb-dev |
mariadb-openrc | v3.8 | separate scripts, in past was embebed on server package | . |
Initialization
The alpine package of MySQL/MariaDB are like normal tarball of MySQL one, admins must know what they want.. there's no automatic window-like installation here.
The datadir located at /var/lib/mysql
must be owned by the mysql user and group. You can modify this behavior but must edit the service file at /etc/init.d
directory. Also, you need to set datadir=<YOUR_DATADIR>
under section [mysqld]
at the config file.
- Initialize the main mysql database, and the data dir as standardized to
/var/lib/mysql
by the rc script.
/etc/init.d/mariadb setup - Then you can start the service but there's no root password set until this point.
/etc/init.d/mariadb start - Secure the installation by running
mysql_secure_installation
- Setup permissions for manage others users and databases
Configuration
In order to finish setup into MariaDB now provide this script called mysql_secure_installation
that also are present as mariadb-secure-installation
, too. This script provides minimal and security setup to the database, and here are the questions made explained:
- Enter current password for root (enter for none): If you have previously set up a root password, provide it here and press enter, either just push enter. If correctly entered, the response will be
OK, successfully used password, moving on...
- Switch to unix_socket authentication [Y/n] Setting the root password or using the Unix_socket ensures that only admins can log into engine database, cos we are not production one just pust "n" to setup a root password, which will give you the response
... skipping.
- Change the root password? [Y/n] This gives you the opportunity to change the root password to a stronger one if necessary. So enter "Y" and lest type the new password.. be carefully with that can be remembered.
- Remove anonymous users? [Y/n] Remove anonymous users created to log in using socket authentication. Answering 'Y', resulting in:
... Success!
. - Disallow root login remotely? [Y/n] Normally, root should only be allowed to connect from 'localhost' in order to protect from password sniffing attempts over the network. Enter 'Y' to get:
... Success!
. - Remove test database and access to it? [Y/n] By default, MariaDB comes with a database named 'test' that anyone can access. If this is not needed, 'Y'. The response will be:
... Success!
. - Reload privilege tables now? [Y/n] Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Answer 'Y' and the response will be:
... Success!
.
After responding to each question, restart the service with rc-service mariadb restart
so to make always work on each restart set to default as rc-update add mariadb default
Configuration files and customization
Due today were influenced by systemd standardization, the famous my.cnf are not more the main config file for the server engine. Now only few variables are defined there and all the settings are provided by independent files into the /etc/my.cnf.d/
directory, user own config files are under ~/.my.cnf
config file of each home dir, and are read after global ones; so then we have:
Config file | Path and name | Versions of Alpine | Contents to configure |
---|---|---|---|
my.cnf | /etc/mysql/my.cnf | v2 to v3.8 | All the directives, Global config file |
mariadb-server.cnf | /etc/my.cnf.d/mariadb-server.cnf | since 3.9 | First Global config file, main directives |
.my.cnf | $HOME | all | user name only config directives |
As previously pointed here is the general documentation for normal and common general usage, for professional usage please use Production DataBases : mysql that is the same as MariaDB but with several modifications focused on production and security.
Newer system Alpine packages can set in independent files in any case those commands always works and where are not apply just will ignore the output:
- First lest allowed all incoming connections if we plan to use in our network or remotely, we do not put focus on security cos we must focus on easy usage and/or development:
sed -i "s|.*bind-address\s*=.*|bind-address=0.0.0.0|g" /etc/mysql/my.cnf sed -i "s|.*bind-address\s*=.*|bind-address=0.0.0.0|g" /etc/my.cnf.d/mariadb-server.cnf
- So we are a simple install and not are in domain controller, don't search for hostnames to improve performance responses (ideal for local only servers):
sed -i "s|.*skip-networking.*|skip-networking|g" /etc/mysql/my.cnf sed -i "s|.*skip-networking.*|skip-networking|g" /etc/my.cnf.d/mariadb-server.cnf
Updating or coming from upgrading
Major Upgrades between Alpine Linux version are so easy as change the repository version, but the MySQL/MariaDB engine need some extra steps when this are performed:
Upgrade databases on major releases Upon a major version release of mariadb (for example mariadb-10.1.10-1 to mariadb-10.1.18-1), it is wise to upgrade databases:
- keep the old database (mysql scheme) structure of the engine daemon, currently this are not more the case, today this not make sense anymore
- upgrade the MariaDB/MySQL packages, of course with must be done if the upgrade process to mayor alpine version does not!
- run the
mysql_upgrade -u root -p
script, providing the password or root, (from the new package version) against the old still-running database (mysql scheme). This will produce some error messages; however, the upgrade will succeed. - Restart the service
If are unable to run mysql_upgrade because MySQL cannot start try run MySQL in safemode with mysqld_safe --datadir=/var/lib/mysql/
command and then run the mysql_upgrade -u root -p
script.