How to Install MySQL 8 on Debian 10
MySQL is one of the most popular open source database management systems. In this tutorial, we will show you how to install MySQL 8 on Debian 10 step-by-step.
MySQL 8 is the latest stable version of MySQL at the time of writing. It comes with many new features and performance improvements over previous versions. In this tutorial, we will go through the steps to install MySQL 8 on a Debian 10 server.
Prerequisites
Before starting, make sure your Debian 10 server is up to date:
sudo apt update
sudo apt upgrade
Steps to Install MySQL
Step 1 - Add MySQL Repository
First, we need to add the MySQL APT repository:
sudo apt-get install lsb-release
sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb
sudo dpkg -i mysql-apt-config*
sudo apt update
Step 2 - Install MySQL
Now let’s install the MySQL server package:
sudo apt install mysql-server
During installation, you’ll be prompted to set a root password for MySQL.
Step 3 - Run Security Script
Once MySQL is installed, run the included security script. This will remove some default settings that are insecure:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow remote root login, and remove test databases.
Step 4 - Manage MySQL Service
To start, stop, restart or enable MySQL service to start on boot:
sudo systemctl start mysql
sudo systemctl stop mysql
sudo systemctl restart mysql
sudo systemctl enable mysql
MySQL is now installed and running!
Create a Database and User
Let’s create a test database and user to verify the installation.
First login with root:
sudo mysql -u root -p
Create a database:
CREATE DATABASE mytestdb;
Create a user with permissions:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON mytestdb.* TO 'myuser'@'localhost';
Exit MySQL shell:
exit
Connect to the new database with the user account:
mysql -u myuser -p mytestdb
Enter password when prompted.
Conclusion
We have successfully installed MySQL 8 on Debian 10 and created a database with a user account. MySQL is now ready to be used by your applications. As next steps, you may want to install phpMyAdmin for web-based database administration or connect your preferred programming language to start developing with MySQL.
If you want to learn more about MySQL, please use our MySQL tutorials and MySQL Reference.