How To Install MySQL On Ubuntu, Debian, Mint Kali?


MySQL is a free and opensource database server which is very popular in the opensource community. MySQL is used by a lot of applications and companies like Facebook, Google, etc. In this tutorial, we will learn how to install MySQL into deb or apt-based distributions like Ubuntu, Debian, Mint, and Kali. This guide can be used for other deb or apt based distributions too.

Update Repository Information

It is not a requirement but a best practice to update repository information which will provide us the newest information about MySQL.

$ sudo apt update
Update Repository Information
Update Repository Information

Install MySQL Server From Apt Repository

MySQL Server application is named as mysql-server as package name. We can use apt or apt-get in order to install mysql-server package like below. We can also use -y option in order to automatically accept conformation.

$ sudo apt install mysql-server
Install MySQL Server From Apt Repository
Install MySQL Server From Apt Repository

Download MySQL Server Binary

Another way to install MySQL is from a binary installation file. We can download MySQL binary from official download site mysql.com. But keep in mind that different versions of MySQL Server are provided with different licenses and costs. We will use community version for Ubuntu which can be listed from the following link.

https://dev.mysql.com/downloads/mysql/

and we will download the deb package with wget.

$ wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-server_8.0.11-1ubuntu18.04_amd64.deb-bundle.tar
Download MySQL Server Binary
Download MySQL Server Binary

Install MySQL Binary Deb Package

After the download is completed we will first extract the tar archive like below.

$ tar xvf mysql-server_8.0.11-1ubuntu18.04_amd64.deb-bundle.tar
Install MySQL Binary Deb Package
Install MySQL Binary Deb Package

and we will install the mysql-community-server_8.0.11-1ubuntu18.04_amd64.deb  package with dpkg like below.

$ sudo dpkg -i mysql-community-server_8.0.11-1ubuntu18.04_amd64.deb

Secure MySQL Server Installation

Security is an important part of today’s IT systems. We can make MySQL more secure by using mysql_secure_installation  hardening script. This will run some commands which will change MySQL configuration and harden it. This script will start by asking root password and then ask some questions about security.

$ sudo mysql_secure_installation
Secure MySQL Installation
Secure MySQL Installation

Show MySQL Service or Daemon Status

After the installation is completed and secured we can list the status of the MySQL server. We will use systemctl command with status option to list whether the MySQL daemon is working or not.

$ systemctl status mysql
Show MySQL Service or Daemon Status
Show MySQL Service or Daemon Status

As we can see the daemon is running properly.

LEARN MORE  How To List MySQL / MariaDB Database?

Start MySQL Service/Daemon/Server

If the MySQL service is not started or stopped with a reason we can start MySQL service with start option like below.

$ systemctl start mysql

Stop MySQL Service/Daemon/Server

If we need to stop the MySQL daemon we can use stop option. This can be useful to apply a new configuration by stopping and starting the service.

$ systemctl stop mysql

Test MySQL Server By Logging In

We can test the MySQL server by connecting to the service console with mysql command. We also need to provide the username and the password like below.

$ mysql -u root -p
Test MySQL Server
Test MySQL Server

Leave a Comment