MariaDB

From Alpine Linux
Revision as of 07:51, 23 May 2019 by Andaris (talk | contribs) (Fix typo)

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.

Setup

MariaDB packages can be installed by running

apk add mariadb mariadb-client

Defining variables that will be used for setup and configuration

DB_DATA_PATH="/var/lib/mysql" DB_ROOT_PASS="mariadb_root_password" DB_USER="mariadb_user" DB_PASS="mariadb_user_password" MAX_ALLOWED_PACKET="200M"

Installing mysql database

mysql_install_db --user=mysql --datadir=${DB_DATA_PATH}

Starting service

rc-service mariadb start

You should get something like

 * Caching service dependencies ...                       [ ok ]
 * Starting mariadb ...
161122 09:23:06 mysqld_safe Logging to syslog.            [ ok ]

Setting root password

mysqladmin -u root password "${DB_ROOT_PASS}"

Creating new user, removing security sensitive data

echo "GRANT ALL ON *.* TO ${DB_USER}@'127.0.0.1' IDENTIFIED BY '${DB_PASS}' WITH GRANT OPTION;" > /tmp/sql echo "GRANT ALL ON *.* TO ${DB_USER}@'localhost' IDENTIFIED BY '${DB_PASS}' WITH GRANT OPTION;" >> /tmp/sql echo "GRANT ALL ON *.* TO ${DB_USER}@'::1' IDENTIFIED BY '${DB_PASS}' WITH GRANT OPTION;" >> /tmp/sql echo "DELETE FROM mysql.user WHERE User='';" >> /tmp/sql echo "DROP DATABASE test;" >> /tmp/sql echo "FLUSH PRIVILEGES;" >> /tmp/sql cat /tmp/sql | mysql -u root --password="${DB_ROOT_PASS}"

Modifying configuration file /etc/mysql/my.cnf

sed -i "s|max_allowed_packet\s*=\s*1M|max_allowed_packet = ${MAX_ALLOWED_PACKET}|g" /etc/mysql/my.cnf sed -i "s|max_allowed_packet\s*=\s*16M|max_allowed_packet = ${MAX_ALLOWED_PACKET}|g" /etc/mysql/my.cnf

Normally you want to start the MariaDB server when the system is launching. This is done by adding MariaDB to the needed runlevel.

rc-update add mariadb default

Now MariaDB server should start automatically when you launch your system next time. To test that run:

reboot

To make sure that mysql started run:

ps aux | grep mysql

You should get something like this:

  382 mysql      0:00 /usr/bin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --pid-file=/run/mysqld/mysqld.pid --socket=/run/mysqld/mysqld.sock --port=3306
  383 root       0:00 logger -t mysqld -p daemon.error