For reports on my timeseries data I really needed Windowing functions like LAG(), LEAD(), ROW_NUMBER() etc. The speed and flexibility you gain using Windowing functions is incredible compared to imitating LAG() using “self-join” tricks. But these function are supported as of MySQL 8 and as of MariaDB 10.2.
For numerous of reasons I prefer to use MariaDB which is compatible drop-in replacement for MySQL.
Unfortunately there are no ready to install packages for ARM so you need to compile and install newer versions by hand.
I’ve came across many articles regarding compilation of MariaDB but these did not match my installation and were missing some important steps. So decided to share my solutions.
So let’s start!
This guide assumes you already have MySQL 5.5 up and running. It will stick to the defaults:
log_error = /var/log/mysql/error.log
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr/local/mysql
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
Please note that datadir may refer to a different or the default location: /usr/local/mysql/data. If that’s the case be sure to edit the lines below.
1.1. Become SU
To ease the installation login as su. All the steps in this guide assume you’d logged as su:
1.2. Backup your databases
Export your databases and create a copy of your
The export can easily be done with HeidiSQL or PhpMyAdmin.
1.3 Uninstall MySQL
Uninstall MySQL but do not purge the configuration:
apt-get remove mysql*
apt-get remove mysql
apt-get remove mariadb
apt-get remove mariadb*
2. Updating & Installing prerequisites
apt-get update -y && apt-get upgrade -y
apt-get install -y build-essential pkg-config libgmp-dev nettle-dev nettle-bin pkg-config autogen git cmake scons libarchive-dev libevent-dev libssl-dev libboost-dev libncurses5-dev libbison-dev cmake libaio-dev libjemalloc-dev libjemalloc1 libncurses5-dev bison libxml2 libxml2-dev libzstd-dev zstd default-jre zlib1g-dev
3. Install gnutls 3.3.24
For some reason the compilation of MariaDB requires exactly version 3.3.24 of gnutls. So let’s install it:
unxz gnutls-3.3.24.tar.xz && tar -xvf gnutls-3.3.24.tar
./configure && make && make install
ln -s /usr/local/lib/libgnutls.so.28 /usr/lib/libgnutls.so.28
Verify the version:gnutls-cli -v
4. Download, compile and install MariaDB
The compilation of MariaDB’s (the
make statement) sources may take up to 10 hours on some older Raspberry PI models. So please be patient.
tar xvf mariadb-10.3.8.tar.gz
cmake . -DBUILD_CONFIG=mysql_release
5. Configure users and folder ownership
groupadd mysql && useradd -g mysql mysq
chown -R mysql /usr/local/mysql/
chgrp -R mysql /usr/local/mysql
chown -R mysql /var/lib/mysql/
chown -R mysql /usr/share/mysql/
chown -R mysql /var/log/mysql/
6. Configure the service
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
update-rc.d mysql defaults
7. Deploy base tables
If you do not want to use my.cnf during initial table creation you can use this line:
/usr/local/mysql/scripts/mysql_install_db --user=mysql --no-defaults --basedir=/usr/local/mysql --datadir=/var/lib/mysql
8. Restore my.cnf
If not preserved you can now restore your my.cnf or the entire /etc/mysql folder.
For reference here is the default my.cnf found on a typical Raspbian installation:
# # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # This will be passed to all mysql clients # It has been reported that passwords should be enclosed with ticks/quotes # escpecially if they contain "#" chars... # Remember to edit /etc/mysql/debian.cnf when changing the socket location. [client] port = 3306 socket = /var/run/mysqld/mysqld.sock # Here is entries for some specific programs # The following values assume you have at least 32M ram # This was formally known as [safe_mysqld]. Both versions are currently parsed. [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr/local/mysql datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking # # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 0.0.0.0 # # * Fine Tuning # key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover = BACKUP #max_connections = 100 #table_cache = 64 #thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 1M query_cache_size = 16M # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! general_log_file = /var/log/mysql/mysql.log general_log = 1 # # Error log - should be very few entries. # log_error = /var/log/mysql/error.log # # Here you can see queries with especially long duration #slow_query_log_file = /var/log/mysql/mysql-slow.log #slow_query_log = 1 #long_query_time = 2 #log_queries_not_using_indexes # # The following can be used as easy to replay backup logs or for replication. # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer = 16M # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/
9. Start the service
sudo /etc/init.d/mysql start
If for some reason you receive
[ERROR] Can't find messagefile '/usr/share/mysql/errmsg.sys'then manually copy the file:
cp /usr/local/mysql/share/english/errmsg.sys /usr/share/mysql
On failure you can check the logs located in /var/log/mysql. There’s also a handy guide to troubleshoot MySQL starting problems. My observations are that most startup problems are due to insufficient permissions on some MySQL core folders.
10. Change MySQL root’s password
By default root’s password is empty string. It is strongly recommended to change it:
If this script fails to connect then use
mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!';
11. Restore your databases
Using HeidiSQL or PhpMyAdmin restore your databases.
12. Remove temp directories
rm -rf /mariadb
rm -rf /gnutls-3.3.24
Well…that’s it. Now you have the power of Windowing functions and much more 🙂