How to install MySQL on Ubuntu 18.04

How To Install MySQL on Ubuntu 18.04 LTS

MySQL is the most popular open source SQL database management system with around 6 million installations worldwide. MySQL was built and maintenance by MySQL AB before Sun Microsystems Inc take acquisition action against MySQL AB on January 16, 2008. And finnaly one year later, Oracle’s turn to acquire Sun Microsystems Inc. Since then, MySQL has officially become a family of Oracle products.

MySQL Installation Steps

At this article we will explain how to install MySQL on Ubuntu 18.04 TLS. We are going to use the Ubuntu repository as MySQL sources. In general there are three step to install MySQL database, namely :

Update Local Ubuntu Repository

As we are always doing on Ubuntu environment, every we want to install new software/application we have to update the local repository first. This is must be done to ensure if the software we are using/download from repository is the newest one.

ramans@ubuntu:~$ sudo apt-get update

Install MySQL on Ubuntu

ramans@ubuntu:~$ sudo apt-get install mysql-server 
MySQL installation process

Verifying MySQL Installation

So far, the MySQL installation was completed done. In our Ubuntu server has been running MySQL services. We can use it to store, query and manipulate data inside it. There are so many application uses MySQL as core database, such like : e-commerce, web base application and so on.

Querying MySQL Version

After the MySQL installation was done, we could verify the version of client MySQL by submitting the command:

ramans@ubuntu:~$ mysql --version

We can also check the version of the mysql server by querying the its version by logging in to database.

ramans@ubuntu:~$ sudo mysql -u root -p
 Enter password: 
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 2
 Server version: 5.7.28-0ubuntu0.18.04.4 (Ubuntu)
 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
 Oracle is a registered trademark of Oracle Corporation and/or its
 affiliates. Other names may be trademarks of their respective
 owners.
 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 mysql> show variables where Variable_name = "version";
 +---------------+-------------------------+
 | Variable_name | Value                   |
 +---------------+-------------------------+
 | version       | 5.7.28-0ubuntu0.18.04.4 |
 +---------------+-------------------------+
 1 row in set (0.00 sec)
 mysql> show variables like "%version%";
 +-------------------------+-------------------------+
 | Variable_name           | Value                   |
 +-------------------------+-------------------------+
 | innodb_version          | 5.7.28                  |
 | protocol_version        | 10                      |
 | slave_type_conversions  |                         |
 | tls_version             | TLSv1,TLSv1.1,TLSv1.2   |
 | version                 | 5.7.28-0ubuntu0.18.04.4 |
 | version_comment         | (Ubuntu)                |
 | version_compile_machine | x86_64                  |
 | version_compile_os      | Linux                   |
 +-------------------------+-------------------------+
 8 rows in set (0.01 sec)

The version of our MySQL is 5.7.28.

Securing MySQL

To enhance our MySQL database security, we have to take several step for this, namely : removing test user, implement password policy, etc. These steps are recommended for fresh installation to minimize the vulnerabilities that could be happned on the future. Thanks for the community who has provided the simple script for implementing this step. The script is could be obtained with :

ramans@ubuntu:~$ sudo mysql_secure_installation
Securing MySQL installation
ramans@ubuntu:~$ sudo mysql_secure_installation
Securing the MySQL server deployment.
 Connecting to MySQL using a blank password.
 VALIDATE PASSWORD PLUGIN can be used to test passwords
 and improve security. It checks the strength of password
 and allows the users to set only those passwords which are
 secure enough. Would you like to setup VALIDATE PASSWORD plugin?
 Press y|Y for Yes, any other key for No: Y
 There are three levels of password validation policy:
 LOW    Length >= 8
 MEDIUM Length >= 8, numeric, mixed case, and special characters
 STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file
 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
 Please set the password for root here.
 New password:
 Re-enter new password:
 Estimated strength of the password: 100
 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
 By default, a MySQL installation has an anonymous user,
 allowing anyone to log into MySQL without having to have
 a user account created for them. This is intended only for
 testing, and to make the installation go a bit smoother.
 You should remove them before moving into a production
 environment.
 Remove anonymous users? (Press y|Y for Yes, any other key for No) : N
 … skipping.
 Normally, root should only be allowed to connect from
 'localhost'. This ensures that someone cannot guess at
 the root password from the network.
 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
 Success.
 By default, MySQL comes with a database named 'test' that
 anyone can access. This is also intended only for testing,
 and should be removed before moving into a production
 environment.
 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N
 … skipping.
 Reloading the privilege tables will ensure that all changes
 made so far will take effect immediately.
 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
 Success.
 All done!
Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *