16) Installing MySQL on your Raspberry Pi

<-- Previous    Next –>

The installation of MySQL onto the Raspberry Pi should be straight forward. However, there is an issue that can catch you out to do with the file system size. If there is not enough space on the SD card, the installation will fail, so you should check that first.

Check the file size on your SD card

Run the following 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 below to install MySQL.

To install MySQL

sudo apt-get install mysql-server php-mysql -y

If this fails and gives a message saying that it is unable to find MySQL, try installing MariaDB using the following:

sudo apt-get install mariadb-client mariadb-server

To secure your MySQL installation

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

Note that you should use sudo to run this command as it requires root privileges.

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 sudo mysql_secure_installation and follow the prompts.

<-- Previous    Next –>