MySQL is an Oracle-backed open source relational database management system based on Structured Query Language (SQL).
This tutorial will describe how to install MySQL database server on an Ubuntu 18.04 Server.
Prerequisites
To follow this tutorial, you will need:
One Ubuntu 18.04 Server set up by following this initial server setup guide, including a sudo non-root user and a firewall.
Step 1 - Installing MySQL
At the time of writing this article, the latest version of MySQL available from the official Ubuntu 18.04 repositories is MySQL version 5.7.
To install MySQL on the Ubuntu server, we will follow the steps below:
First, update the apt package index:
$sudo apt update
Then, install the MySQL Server package by typing the command:
$sudo apt install mysql-server
After completing the installation, the MySQL service will start automatically. To check if the MySQL service is running, type the command below:
$sudo systemctl status mysql
You’ll see output similar to the following:
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2020-10-18 18:02:27 -03; 9s ago Main PID: 3019 (mysqld) Tasks: 27 (limit: 1098) CGroup: /system.slice/mysql.service └─3019 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Step 2 - Securing MySQL
The MySQL installation comes with a script called mysql_secure_installation
to run after installation and to configure some important security settings.
Run the security script by typing:
$sudo mysql_secure_installation
When executing this command, you will be asked if you would like to configure the ** Validate Password Plugin ** , which can be used to test the strength of your password in MySQL and improve the security. There are three levels of password validation policy, low, medium and strong. Press ENTER if you don’t want to use this plugin.
On the next question at the prompt, will be to set your password for the root user of MySQL. The script will also ask you to remove the anonymous user, restrict root user access to the localhost snd remove the test database. For these questions, you must answer Y
Step 3 - Check Installation
To finish the installation, we will check the status of the service.
$sudo systemctl status mysql.service
You'll see output similar to the following:
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2020-10-18 18:02:27 -03; 1min 24s ago Main PID: 3019 (mysqld) Tasks: 29 (limit: 1098) CGroup: /system.slice/mysql.service └─3019 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
If MySQL is not running, you can start it with the command below:
$sudo systemctl start mysql
Let's confirm the version that was installed with the command:
$sudo mysqladmin -p -u root version
You should see output similar to this:
mysqladmin Ver 8.42 Distrib 5.7.31, for Linux on x86_64 Copyright (c) 2000, 2020, 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.
Server version 5.7.31-0ubuntu0.18.04.1 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 1 min 45 sec
Threads: 1 Questions: 10 Slow queries: 0 Opens: 107 Flush tables: 1 Open tables: 100 Queries per second avg: 0.095
This means MySQL is up and running.
Conclusion
You now have a basic MySQL configuration installed on your server securely.
0 COMMENTS