How to Install MySQL on a Raspberry Pi
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
MySQL is a popular open-source relational database management system, well-suited for web and server applications. Installing it on a Raspberry Pi can turn this compact device into a robust server for managing data. This guide provides a straightforward approach to setting up MySQL on a Raspberry Pi.
Before proceeding, ensure your Raspberry Pi is up to date:
sudo apt update
sudo apt upgrade
To install MySQL, use the following command:
sudo apt install mysql-server
After installation, secure your MySQL installation:
sudo mysql_secure_installation
Follow the prompts to set a root password and configure security options.
Initially, access MySQL with the root user:
sudo mysql -u root -p
Enter the root password when prompted.
For security reasons, it’s recommended to create a new user:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Replace username and password with your preferred credentials.
Create a database for your applications:
CREATE DATABASE exampledb;
Replace exampledb with your desired database name.
To access and manage your database, log in with your new user:
mysql -u username -p
Enter the password when prompted.
To control the MySQL service, use the following commands:
sudo systemctl start mysql # To start MySQL service
sudo systemctl stop mysql # To stop MySQL service
sudo systemctl enable mysql # To enable MySQL on boot
sudo systemctl disable mysql # To disable MySQL on boot
With MySQL installed on your Raspberry Pi, you now have a powerful tool for managing data. Whether for web applications, IoT projects, or learning SQL, your Raspberry Pi is now ready for database management tasks.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.