I’ve had a few people ask me lately about how I got MySQL running on my Raspberry Pi, so here’s my guide on how to go from almost 0 to 100. This guide assumes you understand the basics of Linux and Raspberry Pi’s. You’ve probably done a few different tutorials and you have tinkered with it before.
1. Download Raspbian.
2. Wipe the sd card and format it. (SDFormatter is a free tool you can use.)
3. Unzip the file.
4. Write the image to disk. (Win32 Disk Imager is a free tool you can use.)
5. Copy a wpa_supplicant.conf file and ssh.txt over to the boot partition of the sd card. You’ll need to edit the conf to contain your current wifi information, the below is a good example of a file you can modify and use. The ssh.text file is just a blank file with the name ssh so the Pi knows to enable SSH on boot.
country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="YOUR WIFI IS GONNA GO HERE" scan_ssid=1 psk="YOUR PASSWORD IS GOING HERE AND IF YOU DON'T USE ONE THEN SHAME ON YOU" key_mgmt=WPA-PSK }
6. SSH into the PI. (Putty is a free tool you can use.)
7. Run this on your Pi to get RDP working. It’s just a nice to have but you can skip this if you won’t use it, we won’t be using it in the tutorial.
#remove the following packages : xrdp, vnc4server, tightvncserver sudo apt-get remove xrdp vnc4server tightvncserver #install tightvncserver followed by xrdp sudo apt-get install tightvncserver sudo apt-get install xrdp
8. Now update the Pi so it’s current.
#update your system's package list by entering the following command: sudo apt-get update #Next, upgrade all your installed packages to their latest versions with the command: sudo apt-get dist-upgrade
8. Get My-SQL.
sudo apt-get install mysql-server
9. Configure security for MySQL, this is going to ask you about creating a root user. Make sure you give it a password, MyPHPAdmin will NOT work if you don’t make your root user with a password. I made this mistake the first time and then installed phpmyadmin, this was where the root password got stored and I had to re-run the configuration for phpmyadmin by following the steps posted below: (Credit to Amigo Chan on askUbuntu) (For anyone googling this error, I saw errors such as “not enough privilege to view users. phpmyadmin” and “access denied for user ‘root’@’localhost’ TO DATABASE phpmyadmin”.)
sudo mysql_secure_installation
10. Install bindings for python for later use.
sudo apt-get install python-mysqldb
11. Create a mysql user.
sudo mysql -u root -p GRANT ALL PRIVILEGES ON mydb.* TO 'USERNAME'@'localhost' IDENTIFIED BY 'PASSWORD GOES HERE'; quit
12. Get apache2 up and running.
sudo apt-get install apache2 php5 libapache2-mod-php5
13. Get phpmyadmin up and running.
sudo apt-get install phpmyadmin
14. Configure apache2.
sudo nano /etc/apache2/apache2.conf
15. Restart apache2.
sudo /etc/init.d/apache2 restart
16. Now you need to go to a webbrowser and put in the IP of the Pi and /phpmyadmin at the end. Example(192.168.1.155/phpmyadmin)
And Voila! You should be in!
Additional resources used:
https://pimylifeup.com/raspberry-pi-mysql-phpmyadmin/