In this article, I’ll show you how to install MySQL on a Linux server.
My server is running Debian 9 Stretch. However, you can use this same process on almost any Linux server.
Fetch New Versions of Packages
You will install MySQL using APT.
APT is a tool that handles the installation and removal of software packages on Linux.
First, run these two commands to fetch new versions of packages:
sudo apt-get update sudo apt-get upgrade


Install MySQL
To install MySQL, run the following command:
sudo apt-get install mysql-server

You will be asked to set a password for the MySQL root user. Set a strong password, and don’t forget to keep it in a safe place. You will need it later to create and manage databases and database users.
MySQL or MariaDB?
Currently, there is a trend of replacing MySQL server with MariaDB.
Don’t be surprised if, after running the above-mentioned commands, you end up with MariaDB being installed instead of MySQL.
In many, if not most, Linux distributions today, MySQL installation packages are replaced by MariaDB.
MariaDB is a fork of MySQL created by the original developers of MySQL after MySQL was bought by a big corporation (Sun, then Oracle). In terms of performance and functionality, they are both equal.

Check If MySQL/MariaDB Is Installed and Running
When you are done, you can check if MySQL/MariaDB is installed and running properly.
Do so by running one of the following commands:
sudo mysql

sudo mysql --version

sudo service mysql status

sudo /etc/init.d/mysql status

Based on the response, you can tell if MySQL/MariaDB is installed and running or not.
Conclusion
Installing MySQL (or MariaDB) on Linux is a simple process that involves the following steps.
- Fetch new versions of installation packages.
- Install MySQL/MariaDB using apt-get install.
- Set a root password.
- Check if MySQL/MariaDB is installed and running properly.