element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
BeagleBoard
  • Products
  • Dev Tools
  • Single-Board Computers
  • BeagleBoard
  • More
  • Cancel
BeagleBoard
Blog BeagleBone Web Server - MySQL Installation
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join BeagleBoard to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: oneleggedredcow
  • Date Created: 23 Nov 2013 12:52 AM Date Created
  • Views 3653 views
  • Likes 1 like
  • Comments 8 comments
Related
Recommended

BeagleBone Web Server - MySQL Installation

oneleggedredcow
oneleggedredcow
23 Nov 2013

Table of Contents

Setup

LED Blinking

MySQL Installation

Temperature Sensor

Introduction

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.

 

Installing MySQL

Before we start, if you have not updated opkg in a while, you should probably do that first:

 

opkg update

 

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:

 

/etc/init.d/mysqld start

 

We will see an error:

 

/etc/init.d/mysqld: line 3: /etc/default/rcS: No such file or directory

image

The fix to this issue is fairly easy.  We need to comment out that line 3 in the script:

 

vi /etc/init.d/mysqld

image

Now when we try and fire up MySQL:

 

/etc/init.d/mysqld start

 

We are successful and we can log into MySQL:

image

Warning

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.)

 

MySQL Configuration

To fix that issue, we need to make some more configuration changes.  First we need to remove some unnecessary links:

 

rm /etc/rc*/*mysqld

image

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:

 

vi /lib/systemd/system/mysql.service

 

And put the following text in that file:

 

[Unit]

Description=MySQL database server

After=syslog.target

After=network.target

 

[Service]

ExecStart=/usr/bin/mysqld_safe

ExecStop=/bin/kill -15 $MAINPID

PIDFile=/var/lib/mysql/mysql.pid

Restart=always

 

[Install]

WantedBy=multi-user.target

 

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

image

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:

 

#include <mysql.h>

#include <stdio.h>

 

int main(void)

{

                printf(“MySQL client version: %s\n”, mysql_get_client_info());

 

return 0;

}

 

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:

 

./test

image

Now MySQL should be installed on your BeagleBone and ready to use!

 

Video

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Next Article

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.

  • Sign in to reply
  • shabaz
    shabaz over 9 years ago in reply to sesiomedec

    Hi Moises,

     

    I could be wrong, but that usually happens when you have unusual characters in the code (e.g. if copied-and-pasted from a web page).

    Unless you have a text editor that allows you to examine it and remove them, you'll just have to manually type it rather than

    copy-and-paste (or try to hit delete on the end of lines and carriage returns, and also delete quotations-marks and re-type them, etc).

    If you look closely at speech-marks in a web page, you'll sometimes notice that the opening speech mark is angled differently from the closing

    speech-mark, i.e. they are different characters. Yet in C/C++ world, only one type of speech-mark is used for opening and closing.

    So, sometimes copying-and-pasting from a web page messes with the code.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • sesiomedec
    sesiomedec over 9 years ago

    Hello Shaun Endres, thank you for posting this excellent tutorial for begginers like me, Im a little bit stucked in the compilation process of test c program, I'm getting this error:

     

    root@beaglebone:~/ParcaseDBpgrms# g++ test_MysqlScript.c -o test -I/usr/include/mysql/ -lmysqlclient

    test_MysqlScript.c:11:17: error: stray '\342' in program

    test_MysqlScript.c:11:17: error: stray '\200' in program

    test_MysqlScript.c:11:17: error: stray '\234' in program

    test_MysqlScript.c:11:17: error: stray '\' in program

    test_MysqlScript.c:11:17: error: stray '\342' in program

    test_MysqlScript.c:11:17: error: stray '\200' in program

    test_MysqlScript.c:11:17: error: stray '\235' in program

    test_MysqlScript.c: In function 'int main()':

    test_MysqlScript.c:11:27: error: 'MySQL' was not declared in this scope

     

    do you know any reason for this to happen?  I have to say that when intalled the libmysqlclient-dev libraries it got stucked in configuring lighttpd and I have to ^C. From the very beginning of the tutorial its always getting stucked in this step but I think everything workd ok besides the libmysqlclient-dev step :S...

     

    Thanks in advance!!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • oneleggedredcow
    oneleggedredcow over 11 years ago in reply to Former Member

    The previous entry in this series shows how to write to a digital output from a webpage.  And the next entry goes over how to show temperature values in a web page.

     

    If you want a more dynamic website, then I would suggest checking out web sockets.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 11 years ago

    Hi, I need to write digital Outputs in Beaglebone black from a web page, and show digital inputs and 1wire termometers values in this web page each second.

    I think to use a c++ program to do the hardware interface, I need some help to communicate the web page with de C++ program.

    Coud you give some light.

    Thanks.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • oneleggedredcow
    oneleggedredcow over 11 years ago in reply to Former Member

    Excellent, thanks for the heads up.  I just corrected the typo.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube