How ToLinuxUbuntu

How to install MySQL on Ubuntu (Linux)

You can easily install MySQL (Open-Source Relational DBMS) on your Ubuntu/Linux.

MySQL is an open-source relational database management system powered by Oracle. It is named after its co-founder Michael Widenius’s daughter My Widenius and SQL stands for Structured Query Language. Installing MySQL on Ubuntu, you can manage tasks like data warehousing, maintaining a web database, and can be used to store every single thing in an inventory.

Installing MySQL client on Ubuntu (Linux) requires just a few lines of code. You are going to install MySQL using the Ubuntu Repositories. It is applicable to Ubuntu 18.04, 16.04, and other versions.

Codes and Steps to install My SQL on Ubuntu using Repositories

MySQL on Linux

Before getting into the steps, make sure that your Ubuntu server is loaded with Sudo privileges.

(1) At first, update the apt package index on your server.

sudo apt update

(2) Now, its time to install MySQL. Type the below code.

sudo apt install mysql-server

If you want to install secure utility for your server, type,

sudo mysql_secure_installation utility

This will asks you to specify the root password and other security-related settings.

If you want to enable remote access from another system, run the following command.

sudo ufw enable
sudo ufw allow mysql

Now, you have installed MySQL and all the required things. Run the command below to start the MySQL.

sudo systemct1 start mysql

The output will be similar to the below

mysql.service – MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-02-18 11:30:23 PDT; 10min ago
Main PID: 11111 (mysqld)
Tasks: 11 (limit: 2321)
CGroup: /system.slice/mysql.service
`-11111 /usr/sbin/mysqld –daemonize –pid-file=/run/mysqld/

After that, you can use the following code to log in to the MySQL.

sudo mysql

The output will be,

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.22-0ubuntu18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, 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

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

To make the MySQL runs after reboot, type,

sudo systemct1 enable mysql

If you are stuck in the middle of a process, then kill the process and proceed further.

How to uninstall MySQL on Ubuntu

If you are done with MySQL, you can uninstall it with ease.

As a first step, disable all the services that are linked to MySQL.

sudo systemctl stop mysql.service && sudo systemctl disable mysql.service

Now, type the below code to say goodbye to MySQL.

sudo apt purge mysql*

To clean up all the MySQL related files, type

sudo apt autoremove

By using the above steps and codes, you can install MySQL on your Ubuntu. Use the MySQL for your database management and other tasks. If you have any doubts in the installation process or any other Linux related queries, tell us in the comments section.

Don’t forget to follow us on Facebook and Twitter. Stay connected with us on our social handles.

Was this article helpful?

Related Articles

Leave a Reply

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

Back to top button