MySQL is a very popular open source database. In this project, we will use it to store the measured temperature values, which can then be retrieved by a web page.
Before we start, if you have not updated opkg in a while, you should probably do that first:
Now on to the task at hand. Installing MySQL. There is already an opkg package, so we’ll install that:
opkg install mysql5
This will download and install MySQL. Unfortunately, if we try and fire up MySQL:
We will see an error:
/etc/init.d/mysqld: line 3: /etc/default/rcS: No such file or directory
The fix to this issue is fairly easy. We need to comment out that line 3 in the script:
Now when we try and fire up MySQL:
We are successful and we can log into MySQL:
At this point it might seem like time for celebration. We have MySQL installed and are able to run it and log in. Unfortunately, if we restart then when we log in again we will get an error stating:
Cannot make/remove an entry for the specified session.
This is really annoying since it won’t let you log in and fix the issue. I had to resort to reimaging my SD card and trying again. (The steps are here, in case you have to do it as well.)
To fix that issue, we need to make some more configuration changes. First we need to remove some unnecessary links:
Now this prevents MySQL from starting at boot. Since we want MySQL to start at boot, let’s see if we can fix that. To do this, we need to create a new configuration file:
And put the following text in that file:
Description=MySQL database server
ExecStop=/bin/kill -15 $MAINPID
Now we can enable the MySQL service to start at boot and then start the MySQL service:
systemctl enable mysql.service
systemctl start mysql.service
Then we should be able to check the status of the service and make sure that it is running:
systemctl status mysql.service
Now you should be able to restart without getting the log in error and MySQL should be running!
Installing MySQL Client Library
The last thing that we need to do is install the MySQL C programming client library:
opkg install libmysqlclient-dev
Now, let’s test to make sure that it installed correctly and works. To do this, create small test script:
printf(“MySQL client version: %s\n”, mysql_get_client_info());
This will print out the version information for the MySQL client. To build it type:
g++ test.cpp -o test -I/usr/include/mysql –lmysqlclient
And then to run it, type:
Now MySQL should be installed on your BeagleBone and ready to use!
In the next article, we will create a C program that will measure the temperature of the room. It will then write the current temperature into the MySQL database. Finally, we will create a web interface to retrieve and plot the measured temperatures of the room.