Raspberry Pi Configuration for MySQL#
Raspberry Pi Hardware:
Raspberry Pi 3 B+
Update System (Optional)#
Regardless of when you installed the Raspberry Pi, this step may not be necessary, but updating the system may make things easier in some cases and more complicated in rare cases.
Enter the following commands in the terminal:
sudo apt-get update
sudo apt-get upgrade
Installation#
1. Install MySQL#
Enter the following command in the terminal to install MySQL:
sudo apt install mariadb-server
2. Configure the Database#
In the terminal, run the MySQL
secure installation command:
sudo mysql_secure_installation
At this point, the system will ask you: Enter current password for root (enter for none):
, press Enter because there is no password for the first login.
Then it will ask you: Set root password?
—— press y to set the password for the root account.
Now, it will prompt New password
, enter your MySQL
password here. Please remember this password. After entering it, press Enter. It will then prompt re-enter new password
, enter the password again and press Enter.
Next, it will ask you Remove anonymous users
, press y.
Then, it will ask you Disallow root login remotely
, press y.
Then, it will ask you Remove test database and access to it
, press y.
Next, it will ask you Reload privilege tables now
, press y.
Finally, you will see the messages All done!
and Thanks for using MariaDB!
, indicating that the setup is complete.
3. Add a Database#
Run MySQL in the terminal:
sudo mysql -u root -p
Log in using the root password you just set.
After that, you will see Welcome to the MariaDB monitor.
, indicating that you have entered MySQL.
Use MySQL commands to create a database.#
For example, here we create a database named "lingshundb":
create database lingshundb;
Note: Remember to end with a semicolon.
After successfully entering the command to create the database, you should see Query OK
, indicating that the creation was successful.
View the newly created database#
show databases;
Create a MySQL user#
Create a user to assign to the database you just created.
For example, create a user named "lingshun":
create user 'lingshun'@'localhost' IDENTIFIED BY 'YOURPASSWORD';
Grant database access to the user#
Grant the "lingshun" user access to the "lingshundb" database.
GRANT ALL PRIVILEGES ON lingshundb.* TO 'lingshun'@'localhost' IDENTIFIED BY 'YOURPASSWORD';
Note: You need to enter the password you set after IDENTIFIED BY.
Refresh database privileges#
To make the changes take effect, you need to refresh the database privileges.
Enter the following command:
FLUSH PRIVILEGES;
Exit MySQL#
quit
You will see "bye", indicating that you have exited MySQL and returned to the terminal prompt.