MySQL is free and opensource database server which is very popular in opensource community. MySQL is used by alot of applications and companies like Facebook, Google etc. In this tutorial we will learn how to install MySQL into
apt based distributions like Ubuntu, Debian, Mint and Kali. This guide can be used for other
apt based distributions too.
Update Repository Information
It is not a reuirement but a best practice to update repository information which will provide us the newest information about MySQL.
$ sudo apt update
Install MySQL Server From Apt Repository
MySQL Server application is named as
mysql-server as package name. We can use
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
Download MySQL Server Binary
Another way to install MySQL is from binary installation file. We can download MySQL binary from official download site mysql.com . But keep in mind that different versions of MySQL Server is provided with different licenses and costs. We will use community version for Ubuntu which can be listed from following link.
and we will download the
deb package with
$ wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-server_8.0.11-1ubuntu18.04_amd64.deb-bundle.tar
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
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 Installation
Security is important part of the today 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
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
As we can see the daemon is running properly.
Start MySQL Service or Daemon
If the MySQL service is not started or stoped with a reason we can start MySQL service with
start option like below.
$ systemctl start mysql
Stop MySQL Service or Daemon
If we need to stop the MySQL daemon we can use
stop option. This can be useful to apply new configuration by stopping and starting the service.
$ systemctl stop mysql
Test MySQL Server
We can test 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