Before anything else this guide was written and tested on a BeagleBone with Angstrom image 2012.01.27, MySQL version 5.0. If you haven’t updated your Angstrom Image – do so here, update software and backup your SD card as seen here
So last time I showed how to stop the existing node.js server stuff that shows the getting started stuff. If your going to setup anything with these guides – go back and stop those other services first. This will be the first of several guides to get a web server up and running with PHP and MySQL support.
..and yes, there will be a number of ways you could do this – this is only the way we did it. If you can do it better that’s great.
Jump over to MySQL and find the source code in the copy the link from the download section, decompress it, and then configure it.
opkg -V2 update opkg -V2 install glibc-utils mkdir ~/mysql cd ~/mysql wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.95.tar.gz/from/http://mysql.mirrors.ilisys.com.au/ gzip -d ./*.tar.gz tar -xvf ./*.tar cd mys* ./configure --prefix /usr/local/mysql make make install
Woo, ok. Next create the file /etc/init.d/mysql and fill it with the following
#!/bin/sh
# Begin /etc/init.d/mysql
#source /etc/init.d/functions
case "$1" in
start)
echo -n "Starting mysql..."
/usr/local/mysql/bin/mysqld_safe > /dev/null 2>&1 &
#evaluate_retval
;;
stop)
echo -n "Stopping mysqld..."
kill `cat /usr/local/mysql/var/beaglebone.pid`
#evaluate_retval
;;
restart)
$0 stop
/usr/bin/sleep 1
$0 start
;;
status)
if [ -r /usr/local/mysql/var/beaglebone.pid ]; then
content=$(cat /usr/local/mysql/var/beaglebone.pid)
echo "MySQL running - Process:"
echo $content
elif [ -f /usr/local/mysql/var/beaglebone.pid ]; then
echo "Cannot Read PID File."
else
echo "MySQL Not running."
fi
#statusproc /usr/bin/mysqld
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
# End /etc/init.d/mysql
Once saved create some simlinks to all the diffrent run-level folders, then add a user called mysql.
chmod +x /etc/init.d/mysql update-rc.d mysql defaults groupadd mysql useradd -r -g mysql mysql mkdir /usr/local/mysql/var touch /usr/local/mysql/var/beaglebone.err touch /usr/local/mysql/var/beaglebone.pid chown -R root /usr/local/mysql chown -R mysql /usr/local/mysql/var chgrp -R mysql /usr/local/mysql chmod a+xr /usr/local/mysql/var/beaglebone.pid export PATH=$PATH:/usr/local/mysql/bin/ /usr/local/mysql/bin/mysql_install_db mysqld_safe --user=mysql
Restart, then check MySQL is running:
shutdown -r now /etc/init.d/mysql status


I can’t get mysql to run …
/etc/init.d/mysql status just returns “MySql Not Running”
/etc/init.d/mysql start results in “Starting mysql …” but nothing else, no error, no confirmation of success
I reran the commands in the simlinks-sections and everything works fine, the only output I get is from this line “mysqld_safe –user=mysql”:
mysqld_safe –user=mysql
nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /usr/local/mysql/var
STOPPING server from pid file /usr/local/mysql/var/beaglebone.pid
120430 21:19:38 mysqld ended
thanks very much for this detailed guide, php/lighttpd from the follow up post work like a charm
I’ll take another look as soon as I can.
Any chance of dumping the contents of your mysql error log?
try:
cat /usr/local/mysql/var/beaglebone.err
Also I made a change to the file /etc/init.d/mysql
your going to have to:
update-rc.d -f mysql remove
then change line 26 from:
if [ -r /usr/local/mysql/data/beaglebone.pid ]; then
to:
if [ -r /usr/local/mysql/var/beaglebone.pid ]; then
after that try:
update-rc.d mysql defaults
After that:
/usr/local/mysql/bin/mysql_install_db
shutdown -r now
then check status:
/etc/init.d/mysql status
If that doesn’t work dump your error file again.
Thanks, it works now!
The err.dump for my 1st try were:
120430 21:29:04 [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist
after I applied the changes in your answer to my comment:
120502 18:14:04 [ERROR] /usr/local/mysql/libexec/mysqld: Can’t find file: ‘./mysql/host.frm’ (errno: 13)
120502 18:14:04 [ERROR] /usr/local/mysql/libexec/mysqld: Can’t find file: ‘./mysql/host.frm’ (errno: 13)
120502 18:14:04 [ERROR] Fatal error: Can’t open and lock privilege tables: Can’t find file: ‘./mysql/host.frm’ (errno: 13)
I then found a solution on this site:
http://bugs.mysql.com/bug.php?id=1279
I ran these commands I found at the bug-report and after that I ran mysql_install_db again
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql
I honestly don’t know if the last 3 commands were necessary or if I messed up something with the initial guide, but it seems to work now, thanks again, you saved me lots and lots of time and frustration
Hello,
Thanks for the great tutorial, i just got mysql up and running on my Beaglebone.
Initially my make sequence resulted in error, this was solved doing an update / upgrade of my Beaglebone distribution.
I can confirm that after installing Mysql i also needed to do
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql
to get my mysql server running, otherwise he started and then stopped again.
I’ll now start part 2 of your tutorial, thanks again.
Hi,
That file (http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.95.tar.gz)is no longer available.
what is needed to install through opkg install?
Try http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.96.tar.gz/from/http://cdn.mysql.com/
Should still work.
Let us know how you go.
Thanks Paul,
I was able to build it without errors. It looks like it is the last version using make, newer versions use cmake. making it more difficult (at least for me) to build. I will follow your instruction above for setup.
Jan
Glad to hear.
Hi Paul,
I managed to work my way through to the changed version name and even figured out the correct command. The latest being…
wget http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.27.tar.gz
unless that’s the wrong version?
I’m hung up at the follow2ing error…
mysql-5.5.27/include/heap.h
mysql-5.5.27/COPYING
root@beaglebone:~/mysql# cd mys*
root@beaglebone:~/mysql/mysql-5.5.27# ./configure –prefix /usr/local/mysql
-sh: ./configure: No such file or directory
root@beaglebone:~/mysql/mysql-5.5.27#
I’m pretty much aping your procedure without much understanding. I don’t know unix at all, so please forgive me if my problem is obvious.
Thanks,
Norm
Hi Norm,
I haven’t tested that version of MySQL myself, I’ve only seen what Jan from the above comments have said.
Jan has success with version 5.0.96.
I have a feeling that the newer versions won’t work with this guide. So to get you back on track try the following commands:
rm -r ~/mysql-5.5.27
wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.96.tar.gz/from/http://cdn.mysql.com/
Try picking up from this point in the guide. Let me know how you go.
Hi Paul,
Well, I didn’t get very far. The line that begins “index.html” was unusual in that it counted off from 0% to 100%.
root@beaglebone:~/mysql# wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql -5.0.96.tar.gz/from/http://cdn.mysql.com/
Connecting to dev.mysql.com (137.254.60.11:80)
Connecting to cdn.mysql.com (173.228.66.10:80)
index.html 100% |*******************************| 22154k 0:00:00 ETA
root@beaglebone:~/mysql# gzip -d ./*.tar.gz
gzip: ./*.tar.gz: No such file or directory
Norm
OK, it downloaded – the file size is correct. For some reason it called it “index.html”. I can’t say I know why. I tried it myself and got a different result.
Having said that, we can rename it. Try the following:
mv ~/mysql/index.html ~/mysql/mysql-5.0.96.tar.gz
IF THAT DOESN”T WORK…. we’ll download again try:
wget http://cdn.mysql.com/Downloads/MySQL-5.0/mysql-5.0.96.tar.gz
Let me know.
That worked. This time I made it through the long compiles and as far as “chmod a+xr /usr/local/mysql/var/beaglebone.pid”
beaglebone.err (which is empty) is the only file in that directory.
root@beaglebone:~/mysql/mysql-5.0.96# chgrp -R mysql /usr/local/mysql
root@beaglebone:~/mysql/mysql-5.0.96# chmod a+xr /usr/local/mysql/var/beaglebone.pid
chmod: cannot access `/usr/local/mysql/var/beaglebone.pid’: No such file or directory
Well, we’re getting there.
Apparently I should be a little more careful with my posts.
this time create the pid file by running:
touch /usr/local/mysql/var/beaglebone.pid
then continue.
Again Let me know.
I’m sorry Paul. This is taking up a lot of your time.
This time, after reboot…
Using username “root”.
root@192.168.0.24‘s password:
root@beaglebone:~# /etc/init.d/mysql status
-sh: /etc/init.d/mysql: /bin/sh^M: bad interpreter: No such file or directory
No, no… I don’t mind.
Sometimes Unix can be a little bit picky when you copy paste things from other systems. Check out this guide: http://clearfix.be/2012/05/17/how-to-fix-a-binshm-bad-interpreter-error/
Thanks. That’s going to be useful in general not just on this issue. I created the file on my PC and uploaded with FileZilla ( using SSH File Transfer Protocol) forgetting all about that line ending thing which I should know from doing html.
It says “MySQL not running.” I guess that means I got that file cleaned up ok. Is that called a shell script?
I guess this means I made a typo somewhere but I have no idea where it might be. Can I assume that the build of “mysql-5.0.95″ was ok? Can I repeat the stuff after the build without screwing something up?
Thanks
Ok so can you run:
/etc/init.d/mysql start
/etc/init.d/mysql status
tail /usr/local/mysql/var/*.err
The formatting here is a little odd because of the different line lengths between my SSH window and this edit box.
root@beaglebone:~# /etc/init.d/mysql status
MySQL Not running.
root@beaglebone:~# tail /usr/local/mysql/var/*.err
InnoDB: Doing recovery: scanned up to log sequence number 0 43655
120922 8:52:47 InnoDB: Starting an apply batch of log records to the database. ..
InnoDB: Progress in percents: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 7 5 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
120922 8:52:47 InnoDB: Started; log sequence number 0 43655
120922 8:52:47 [ERROR] /usr/local/mysql/libexec/mysqld: Can’t find file: ‘./mys
ql/host.frm’ (errno: 13)
120922 8:52:47 [ERROR] /usr/local/mysql/libexec/mysqld: Can’t find file: ‘./mys
ql/host.frm’ (errno: 13)
120922 8:52:47 [ERROR] Fatal error: Can’t open and lock privilege tables: Can’t
find file: ‘./mysql/host.frm’ (errno: 13)
120922 08:52:47 mysqld ended
Try this again:
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db
let me know how that goes, then try a restart again:
shutdown -r now
and try the mysql status thing again:
/etc/init.d/mysql status
if that doesn’t work post your error log again:
tail /usr/local/mysql/var/*.err
Wu huu! It’s running.
On to Pt.2
Here’s the output…
root@beaglebone:~# /usr/local/mysql/bin/mysql_install_db
WARNING: The host ‘beaglebone’ could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables…
OK
Filling help tables…
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password ‘new-password’
/usr/local/mysql/bin/mysqladmin -u root -h beaglebone password ‘new-password’
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
Awesome.
Very helpful tutorial. You probably saved me a few days of work. My only problem was that MySQL wasn’t running after the first reboot, and I had to do the permissions again as in the comments above.
Awesome!