Alpine Linux is a minimalist distribution with a focus on security and simplicity.
MariaDB is one of the most popular database servers in the world, created by the original MySQL developers and initially conceived as a direct and improved MYSQL replacement. MariaDB is fast, scalable, and robust, with a rich ecosystem of storage engines, plugins, and other tools that make it versatile and flexible in different scenarios. MariaDB is developed as free software under the GPL license. The latest versions of MariaDB also include GIS and JSON functions.
# apk add mariadb
Administrar el proceso del servidor
In this part we will learn how to start, stop or restart the mariadb service, for this we will use the OpenRC initialization system . OpenRC is the default initialization system on distributions like Gentoo and Alpine Linux.
# rc-service mariadb status * status: stopped
# rc-service mariadb start * Caching service dependencies ... [ ok ] * Datadir '/var/lib/mysql' is empty or invalid. * Run '/etc/init.d/mariadb setup' to create new database. * ERROR: mariadb failed to start
The previous error tells us that we have not initialized/installed the databases so we must execute the following command:
# /etc/init.d/mariadb setup * Creating a new MySQL database ... Installing MariaDB/MySQL system tables in '/var/lib/mysql' ... OK ...
Now we can start the DB server
# rc-service mariadb start * Starting mariadb ... 210413 22:11:45 mysqld_safe Logging to syslog. 210413 22:11:45 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql [ ok ]
Check the status again
# rc-service mariadb status * status: started
Start with the OS
If you want MariaDB will start automatically after a system reboot exec the following command:
# rc-update add mariadb default * service mariadb added to runlevel default
# rc-service mariadb stop * Stopping mariadb ... [ ok ]
Connect to the server
To connect to the DB server we must install the package
# apk add mariadb-client
The mariadb-client package includes the mysql shell so we can run:
# mysql -u root Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.5.8-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.000 sec)
Improve the DB server security:
mysql_secure_installation is a shell script available on Unix systems, and enables you to improve the security of your MariaDB installation in the following ways:
- You can set a password for root accounts.
- You can remove root accounts that are accessible from outside the local host.
- You can remove anonymous-user accounts.
- You can remove the test database, which by default can be accessed by anonymous users.
$ mariadb-secure-installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] Y Enabled successfully! Reloading privilege tables.. ... Success! You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Serie(s): Administering MySQL from the command line, 5 (14)
- How to install MySQL 5.7 on CentOS 7
- How to install MySQL 8.0 in Ubuntu 20.04
- MySQL 8.0, change root password
- How to install MySQL 8.0 in Debian
- How to install MariaDB on Alpine Linux
- MySQL server administration - Basic
- Create / modify / delete tables in MySQL
- MySQL user administration
- MySQL - Execute SQL script
- Disable innodb engine in MySQL
- Show MySQL storage engines
- Character set available in MySQL
- Connect to a MySQL server from the LAN
- MySQL can not write in the /tmp dir