Raspberry Pi MYSQL
This Raspberry Pi MYSQL & PHPMyAdmin tutorial is an extension to the webserver tutorial I did earlier.

If you’re unfamiliar of MYSQL this is a great way to get learning it. MySQL is a relational database management system and allows you store & maintain data. It is one of the world’s most popular relation database system and is commonly included in most LAMP stacks.

For anyone who doesn’t know PhpMyAdmin is a free tool that has been designed to allow for easy administration of MYSQL. It is hugely popular and used in a lot of web server environments throughout the world.

If you want to see how this is all done visually be sure to check out the video, I have put together below. It will take you through from start to finish on how to get this done. As always if you like the video then please subscribe to my channel!

Equipment

Below is the equipment that you will need in order to complete this Raspberry Pi MYSQL tutorial.

Required

Optional

 

Getting Started

As always you will need to have Raspbian installed or a similar operating system installed before we can get started. Be sure to head over to my page on installing Raspbian if you haven’t yet learnt how to do this.

I have broken this tutorial down into two steps, first we will install the web server software and also MYSQL. In the 2nd step we will take a look at installing the PHPMyAdmin. If you have come from the Raspberry Pi web server tutorial, then you can simply skip the first step as you would have already done this.

Installing Raspberry Pi MYSQL

  1. Firstly let’s install the mysql server onto the Raspberry Pi.
    sudo apt-get install mysql-server
  2. You will be prompted to enter a password for the root user. Make sure you write this down as we will need to use this to access the MYSQL server and connect PHPMyAdmin to it.
    mysql setup
  3. Now if you want to access and start make changes to the database simply enter the following command:
    mysql -u root -p
  4. It will now prompt you to enter the password we just created.
  5. You can now enter MYSQL commands to create, alter, delete databases.
  6. You can leave the command line by simply entering quit.

If you want to be able to interact with MYSQL in Python you will need to install the Python bindings as well. You can do this by entering the following command.

sudo apt-get install python-mysqldb

Now we’re done installing the Raspberry Pi MYSQL you may want to install PHPMyAdmin so you have a nice clean interface to work with.

Installing Raspberry Pi PHPMyAdmin

You will find that installing Raspberry Pi PHPMyAdmin is very easy to do any won’t take long at all. It is even faster if you have already installed the MYSQL database and Apache.

  1. I will go on the assumption you have not yet installed apache and PHPMyAdmin. If you have already done my web server tutorial or already have installed just skip this step.
    sudo apt-get install apache2 php5 libapache2-mod-php5
  2. Now let’s install the PHPMyAdmin package, you can do this by entering the following:
    sudo apt-get install phpmyadmin
  3. It will now begin to install. You will be presented with a screen asking the type of web server you want it to run off. Select apache2 as this is the server we just installed.
  4. Next we will need to configure PHPMyAdmin to connect a database. (The one we set up previously in installing the Raspberry Pi MYSQL step or the webserver). To do this select yes at the next prompt.
    PHPMyAdmin setup
  5. It will now ask for a password, enter the one we set previously when we set up MYSQL.
  6. Next it will ask you to set a password for PHPMyAdmin. You can keep it the same as the password to the MYSQL database or something separate. Make sure you remember it as this is the password you will need to access it.
  7. We will also need to setup Apache to include our PHPMyAdmin installation. To do this enter:
    sudo nano /etc/apache2/apache2.conf
  8. Now at the bottom of this file enter the following line:
    Include /etc/phpmyadmin/apache.conf

    Once done save & exist by pressing CTRL +X and then y.

  9. Now simply restart the Apache service by entering the following command:
    sudo /etc/init.d/apache2 restart
  10. Now you should be able to access the PHPMyAdmin from a browser. To test go to the follow address in your browser. (Replace the IP with your IP. If you don’t have it run the command hostname –I on your Pi)
    http://192.168.1.108/phpmyadmin
  11. Raspberry Pi PHPMyAdmin

  12. If it’s all working, then you’re good to go. If you want to learn how to setup WordPress on the Raspberry Pi, then you can find that in my Web Sever tutorial.

If you want to enable external access to the either PHPMyAdmin or MYSQL then you will need to setup port forwarding. To learn how to do this check out my guide on port forwarding. The ports you will need to forward is 80 for PHPMyAdmin and MYSQL is 3306.

If you want to learn more about MYSQL and the commands, you can use to view & edit data then I recommend heading over to w3 schools or at codecademy. They have some great beginner tutorials to help bring you up to speed on using MYSQL.

I hope you are able to get both the Raspberry Pi MYSQL & the PHPMyAdmin working from this tutorial. If you do come across something or feel that I have missed some important steps, then please feel free to drop a comment below.

Share This!
The Raspberry Pi Crash Course

The Raspberry Pi Crash Course

Enter your email address below to get the

Raspberry Pi crash course delivered straight to your inbox

Please check your inbox for a confirmation email!