Install MySQL Server on your Raspberry Pi

I’m writing this article following a number of requests, and a bit of a follow-up to a previous tutorial “Turn your Raspberry Pi 3 into a PHP 7 powered web server“. This tutorial will guide you through steps to install MySQL Server on your Raspberry Pi.

A bit of a word of warning

As mentioned in my replies to a few comments, I don’t recommend running MySQL Server on a Raspberry Pi unless you have a high-quality, high-speed USB flash drive (preferably) or a UHS1/UHS3 class MicroSd card from which you run Raspbian OS. You might want to look at a previous tutorial to learn how to run your Raspberry Pi from a USB Flash drive.

Step 1 – Install MySQL Server

The first thing to do before anything is to ensure that all updates and upgrades are installed. Run the following command:

sudo apt-get update && sudo apt-get upgrade

Once all the updates are installed, we’re ready to install MySQL server. Start by running the following command:

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

This will install the client as well as the server. The client will allow you to connect to your server from the command line which is always handy to do. After a short while, you will see this screen during the installation:

Install MySQL Server on your Raspberry Pi

Go ahead and provide a root password. The root account is the default administration account that allows full control of the locally installed server. You’ll be prompted to repeat this to confirm. Go ahead and type your password again. The installation will finish shortly after.

Step 2 – Connecting to your MySQL server locally

Now we’ve installed MySQL server, we will try connecting to it using the MySQL client we installed at the same time as the server. Type the following command:

mysql -uroot -p

You’ll be prompted for your password again to connect to your MySQL server installation. Congratulations, you’re logged in. You should see something like this:

Install MySQL on Raspbian

Type this command:


This will give you a summary. It should look a little like this:

MySQL on Raspbian OS

This gives us a summary of MySQL Server running on your Raspberry Pi.


We’ve installed MySQL Server and if you’ve followed my previous tutorial to install Apache and PHP 7, you’re ready to start serving a PHP application like WordPress.

I’ll follow-up with another tutorial on installing WordPress in due time.



Web Developer living in Manchester, working for Studio Skylab ( Views and thoughts are my own.

You may also like...

21 Responses

  1. Hi Steve, I’ve ran through a similar tutorial before, and had success running wordpress from a raspberry pi 2 using Nginx.

    Recently,with the added power of the Pi3, I’m attempting a dual wordpress setup on Apache with PHP7 however after following the standard steps, copying the wp-config and editing it to install the database, installing wordpress, I then get stuck on accessing the website from outside the network. It serves pages well within my network, but when trying to access the webpage from outside (testing on my mobile), it will usually time out after 30 seconds.

    I’ve got the ports open to the Pi3, and I’m not sure if there is anything I’m missing regarding steps unless they’re obvious to you?


  2. thijs vogelkop says:

    no secure installation needed?

  3. thijs vogelkop says:

    i am working on nginx with php 7 to make a joomla website, nginx works fine but for the rest HTTP ERROR 500

    • thijs vogelkop says:

      sudo apt-get install php7.0-curl php7.0-gd php7.0-fpm php7.0-cli php7.0-opcache php7.0-mbstring php7.0-xml php7.0-zip

      solves the problems with Joomla and phpMyadmin

  4. Eric B says:

    How do I know if I’m using a “UHS1/UHS3 class MicroSd” card? And why not run MySQL Server on a different card? I’m new to this subject, but am familiar with MySQL Server and would like to eventually start writing temperature data to a database. Any suggestions as to whether or not I should get one of these UHS1/UHS3 MicroSD cards, or is there another database server I could/should use?

  5. steerpike says:

    Easy to follow and it works. Good stuff.

  6. matt vorwald says:

    i’m having no luck running the mysql-server install, actually it works w/o error, but it never prompts for a “root” password. And there i sit, i have no access to my new database!

  7. i just bought a RPI3 and followed the steps.
    after running “sudo apt-get install mysql-server && sudo apt-get install mysql-client”, i do not get an option to set password.
    Hence im unable to proceed with the next step mysql -uroot -p
    please help..

  8. Alberto says:

    Installing “apt-get mysql-server” on Raspberry PI turned out to install MariaDB instead.
    I ran into the same issue described above where after installation I don’t get any chance to set password, anyway when I digit “mysql” over shell, a MariaDB instance runs.
    Kind of weird, if I list all installed packages (“apt list –installed”) I see MariaDB and MySql as well.
    I would prefer to use MySQL over MariaDB for a matter of convention with my development environment.
    Surfing the web it seems to be less documented and I hope someone could find a solution.

    Thanks in advance

    • Ste says:

      It might be that the MariaDb server and the mysql client were installed. As far as I know, mysql client works 100% with MariaDb with MariaDb being a fork of MySql server. Might be wrong though!

      • Alberto says:

        I have mysql client installed as well as mysql server installed, according to the apt packages list I see. I know that mysql client is 100% compatible with MariaDB but I would prefer to find out how to make a mysql server 5.7 up and running on my Raspberry.
        I’ll post right here if I’d come up with something.
        Thanks again

  9. yoeri says:

    doesn’t ask for pw , and doesn’t accept empty box. tutorail seems no longer up to date?

  10. Russell says:

    $ sudo mysql -uroot -p” command and then use password “root” get you to the next step. Sorry that’s all I’ve done so far.

  11. vimal says:

    shell$ sudo mysql -u root

    [mysql] use mysql;
    [mysql] update user set plugin=” where User=’root’;
    [mysql] flush privileges;
    [mysql] \q

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.