15) Installing MySQL on your Raspberry Pi

<-- Previous    Next –>

The installation of MySQL should be straight forward, however, there is an issue that can catch you out to do with the file system size.

To install MySQL use:

sudo apt-get install mysql-server mysql-client php5-mysql

However, this may fail because the filesystem on the SD card will become full. This can be seen by running the command:

sudo df -h

The SD card is probably 4GB. The filesystem will be around 1.9GB. This was done to make it fit on 2GB cards. To stretch the filesystem to the full size you need to run:

sudo raspi-config”

and choose the:

expand_rootfs

option. Then you need to reboot.

Now:

sudo df -h

should tell you that the filesystem has much more free space.

Run the installation script shown above again.

To completely un-install MySQL should your installation fail:

If the installation has failed, you may find it better to un-install MySQL and start again.

To completely un-install MySQL:

sudo service mysql stop #or mysqld
sudo killall -9 mysql
sudo killall -9 mysqld
sudo apt-get remove –purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo apt-get purge mysql-server-core-5.5
sudo apt-get purge mysql-client-core-5.5

To secure your MySQL installation

To further secure your MySQL installation you should use mysql_secure_installation utility in your terminal.

This utility does the following:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.

All you need to do is go into your terminal and type mysql_secure_installation and follow the prompts.

<-- Previous    Next –>