In this post I’ll give to you the steps to compile Percona Server for MySQL 5.7.22 in Raspberry Pi 3. Why? Well because in general this little computer is cheap, has low power consumption, and is great to use as a test machine for developers.
By default Raspbian OS includes very few versions of MySQL to install
|
1 |
$ apt-cache search mysql | grep server<br>...<br>mariadb-server-10.0 - MariaDB database server binaries<br>mariadb-server-10.1 - MariaDB database server binaries<br>mariadb-server-core-10.0 - MariaDB database core server files<br>mariadb-server-core-10.1 - MariaDB database core server files<br>mysql-server - MySQL database server binaries and system database setup [transitional] (5.5)<br>... |
If you want to install MySQL or MariaDB on an ARM architecture using official pre-built binaries, you are limited to those distributions and versions.
Roel Van de Paar wrote time ago this post “Percona Server on the Raspberry Pi: Your own MySQL Database Server for Under $80” using “Fedora ARM” like OS on the first versions of raspberry cards.
Now we will use the last version of Raspberry Pi 3 with Raspbian OS. In my case, the OS version is this
|
1 |
$ cat /etc/issue<br>Raspbian GNU/Linux 9 n l |
Let’s start. We will need many devs packages and cmake to compile the source code. There is the command line to update or install all these packages:
|
1 |
apt-get install screen cmake debhelper autotools-dev libaio-dev wget automake libtool bison libncurses-dev libz-dev cmake bzr libgcrypt11-dev build-essential flex bison automake autoconf bzr libtool cmake libaio-dev mysql-client libncurses-dev zlib1g-dev libboost-dev |
Now we need to download the Percona Server for MySQL 5.7.22 source code and then we can proceed to compile.
Before starting to compile the source code, we will need to extend the swap memory. This is necessary to avoid encountering memory problems at compilation time.
|
1 |
$ dd if=/dev/zero of=/swapfile1GB bs=1M count=1024<br>$ mkswap /swapfile1GB<br>$ swapon /swapfile1GB<br>$ chmod 0600 /swapfile1GB |
Now we can check the memory and find that memory swap is correct
|
1 |
$ free -m |
This is the output in my case
|
1 |
$ free -m<br><br>total used free shared buff/cache available<br>Mem: 927 176 92 2 658 683<br>Swap: 1123 26 1097 |
I recommend to use a screen session to compile the source code, because it takes a lot of time.
|
1 |
$ cd /root<br>$ screen -SL compile_percona_server<br>$ wget https://www.percona.com/downloads/Percona-Server-LATEST/Percona-Server-5.7.22-22/source/tarball/percona-server-5.7.22-22.tar.gz<br>$ tar czf percona-server-5.7.22-22.tar.gz<br>$ cd percona-server-5.7.22-22<br>$ cmake -DDOWNLOAD_BOOST=ON -DWITH_BOOST=$HOME/my_boost .<br>$ make<br>$ make install |
After it has compiled and installed successfully, it’s time to create our datadir directory for this Percona Server version, and the mysql user. Feel free to use other directory names
|
1 |
$ mkdir /var/lib/mysql<br>$ useradd mysql -d /var/lib/mysql<br>$ chown mysql.mysql /var/lib/mysql |
Now it’s time to create a minimal my.cnf config file to start mysql, you can use the below example
|
1 |
$ vim /data/percona-5.6.38/my.cnf<br><br>[mysql]<br>socket=/var/lib/mysql/mysql.sock<br><br>[mysqld]<br>datadir = /var/lib/mysql<br>server_id = 2<br>binlog-format = row<br>log_bin = /var/lib/mysql/binlog<br>innodb_buffer_pool_size = 128M<br>socket=/var/lib/mysql/mysql.sock<br>symbolic-links=0<br><br>[mysqld_safe]<br>log-error=/var/lib/mysql/mysqld.log<br>pid-file=/var/lib/mysql/mysqld.pid |
then we need to initialize the initial databases/schemas, ibdata and ib_logfile files with the next command
|
1 |
$ /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql |
now—finally—it’s time start MySQL
|
1 |
$ /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql & |
We can check if MySQL started or not, by taking a look at the mysqld.log file
|
1 |
$ cat /var/lib/mysql/mysqld.log<br>...<br>2018-08-13T16:44:55.067352Z 0 [Note] Server hostname (bind-address): '*'; port: 3306<br>2018-08-13T16:44:55.067576Z 0 [Note] IPv6 is available.<br>2018-08-13T16:44:55.067680Z 0 [Note] - '::' resolves to '::';<br>2018-08-13T16:44:55.067939Z 0 [Note] Server socket created on IP: '::'.<br>2018-08-13T16:44:55.258576Z 0 [Note] Event Scheduler: Loaded 0 events<br>2018-08-13T16:44:55.259525Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.<br>Version: '5.7.22-22-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution |
In our example it started ok.
Remember MySQL server was installed and started using an alternative path.
Now it’s time to connect and check if everything is running well.
|
1 |
$ /usr/local/mysql/bin/mysql -uroot<br><br>Welcome to the MySQL monitor. Commands end with ; or g.<br>Your MySQL connection id is 4<br>Server version: 5.7.22-22-log Source distribution<br><br>Copyright (c) 2009-2018 Percona LLC and/or its affiliates<br>Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.<br><br>Oracle is a registered trademark of Oracle Corporation and/or its<br>affiliates. Other names may be trademarks of their respective<br>owners.<br><br>Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.<br><br>mysql> show databases;<br>+--------------------+<br>| Database |<br>+--------------------+<br>| information_schema |<br>| mysql |<br>| performance_schema |<br>| sys |<br>+--------------------+<br>4 rows in set (0.00 sec) |
To check the version that’s running, you can use the next command
|
1 |
mysql> SHOW VARIABLES LIKE "%version%";<br>+-------------------------+---------------------+<br>| Variable_name | Value |<br>+-------------------------+---------------------+<br>| innodb_version | 5.7.22-22 |<br>| protocol_version | 10 |<br>| slave_type_conversions | |<br>| tls_version | TLSv1,TLSv1.1 |<br>| version | 5.7.22-22-log |<br>| version_comment | Source distribution |<br>| version_compile_machine | armv7l |<br>| version_compile_os | Linux |<br>| version_suffix | -log |<br>+-------------------------+---------------------+<br>9 rows in set (0.02 sec) |
Keep in mind that you have configured the datadir directory in the same microSD where are you running the OS: MySQL will run slowly. If you create a new table perhaps it will take a few seconds. So, I recommend that you use a separate USB SSD disk, and move the datadir directory to this SSD disk. That’s more useful and the performance is much better
I hope you enjoyed this guide on how to use a tiny server to install Percona Server for MySQL.
If you want to test other versions, please go ahead: the steps will be very similar to these.
Your application or website depend on your database to deliver information about your products and services to your customers. A high traffic event, such as Cyber Monday, can stress the availability of your database. Statistics show that 40% of users abandon a website if it takes longer than three seconds to load. Our preparatory checklist can help your business avoid and mitigate the effects of high traffic events and help keep business running as usual.
In his blog, Percona CEO Peter Zaitsev examines the four ways MySQL executes GROUP BY, a clause that could be responsible for 90% or more of your query’s execution time. Peter also discusses what to do when MySQL GROUP BY does not make the right choice when it comes to resolving the WHERE clause.