MariaDB: Difference between revisions

From Alpine Linux
(Remove setup SQL file (with credentials) after applying it)
(property init the mysql/mariadb page with professional right steps.. part 1)
Line 1: Line 1:
[https://mariadb.org/ 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.
[https://mariadb.org/ 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 =
== Instalation ==
MariaDB packages can be installed by running
{{cmd|apk add mariadb mariadb-client}}


Defining variables that will be used for setup and configuration
Alpine Linux has dummy counterparts packages for those that are not close to that change from ''mysql'' to ''mariadb'' naming packages.
{{cmd|<nowiki>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"</nowiki>}}


Installing mysql database
Take in consideration that the user <code>mysql</code> was created during instalation of packages, in the initialization section two users will be created in database init: <code>root</code> and <code>mysql</code>, and in that point only if are in their respective system accounts, will be able to connect to the database service.
{{cmd|<nowiki>mysql_install_db --user=mysql --datadir=${DB_DATA_PATH}</nowiki>}}


Starting service
<pre><nowiki>
{{cmd|rc-service mariadb start}}
apk add mysql mysql-client
</nowiki></pre>
 
That will install the most used ones.. <code>mariadb-cient</code> and <code>mariadb-server</code>, rest of packages are brief described here for more information:
 
{| class="wikitable"
|-
! 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-c || v3.8 || coding connection on C sources || mariadb-connector-c-dev
|-
| mariadb-connector-odbc || edge || coding or making OS level connections || .
|-
| 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-server-utils || v3.8 || to reduce main server package, not widely used commands || .
|-
| 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 be know what they want.. there's no automatic window-like here,
 
# Initialize the main mysql database, and the data dir as standardized to <code>/var/lib/mysql</code> by the rc script
# Then initialize the service, root account and socket connection are enabled without password at this point
# Setup the root account by asignes a proper password, this are purely paranoid. due next step already do that!
# Setup and init the installation by running the <code>mysql_secure_installation</code>
# Setup permissions for manage others users and databases


You should get something like
<pre>
<pre>
* Caching service dependencies ...                      [ ok ]
<nowiki>
* Starting mariadb ...
mysql_install_db --user=mysql --datadir=/var/lib/mysql
161122 09:23:06 mysqld_safe Logging to syslog.            [ ok ]
</pre>


Setting root password
rc-service mariadb start
{{cmd|<nowiki>mysqladmin -u root password "${DB_ROOT_PASS}"</nowiki>}}


Creating new user, removing security sensitive data
mysqladmin -u root password toor
{{cmd|<nowiki>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}"
rm /tmp/sql</nowiki>}}


Modifying configuration file /etc/mysql/my.cnf
mysql_secure_installation
{{cmd|<nowiki>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</nowiki>}}


Normally you want to start the MariaDB server when the system is launching. This is done by adding MariaDB to the needed runlevel.
{{cmd|rc-update add mariadb default}}


Now MariaDB server should start automatically when you launch your system next time. To test that run:
</nowiki>
{{cmd|reboot}}
</pre>


To make sure that mysql started run:
= See Also =
{{cmd|<nowiki>ps aux | grep mysql</nowiki>}}


You should get something like this:
* [[PotsgreSQL]]
<pre>
* [[Production LAMP system: Lighttpd + PHP + MySQL]]
  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
* [[Alpine newbie developer]]
  383 root      0:00 logger -t mysqld -p daemon.error
* [[Alpine newbie lammers]]
</pre>


[[Category:SQL]]
[[Category:Newbie]]
[[Category:Server]]
[[Category:Server]]
[[Category:Database]]
[[Category:Development]]
[[Category:Security]]
[[Category:Production]]

Revision as of 14:50, 8 March 2020

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.

Instalation

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:

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-c v3.8 coding connection on C sources mariadb-connector-c-dev
mariadb-connector-odbc edge coding or making OS level connections .
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-server-utils v3.8 to reduce main server package, not widely used commands .
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 be know what they want.. there's no automatic window-like here,

  1. Initialize the main mysql database, and the data dir as standardized to /var/lib/mysql by the rc script
  2. Then initialize the service, root account and socket connection are enabled without password at this point
  3. Setup the root account by asignes a proper password, this are purely paranoid. due next step already do that!
  4. Setup and init the installation by running the mysql_secure_installation
  5. Setup permissions for manage others users and databases

mysql_install_db --user=mysql --datadir=/var/lib/mysql

rc-service mariadb start

mysqladmin -u root password toor

mysql_secure_installation



See Also