• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Install MySQL on Ubuntu 20.04

Written by Rahul, Updated on May 23, 2020

MySQL is the popular relational database management system. This tutorial will help you to install and secure MySQL database server on your Ubuntu 20.04 LTS system.

You may like: How to Install phpMyAdmin on Ubuntu 20.04

Prerequisites

Before continuing for MySQL installation on Ubuntu 20.04:

  • Login to Ubuntu as sudo privileged user
  • For the newly installed systems, required to complete initial server setup

Step 1 – Install MySQL Server

The MySQL server 8.0 packages are available under the default repositories on Ubuntu 20.04. After login to your server, update apt cache and run install packages. To install MySQL server type:

sudo apt update
sudo apt install mysql-server

Wait for the package manager to complete the installation.

After finishing the installation, the MySQL service will start automatically. To check the service status type:

sudo systemctl status mysql

Install MySQL Ubuntu 20.04

Step 2 – Secure MySQL Server

At this stage, MySQL server is not secured yet. You can switch to root user of your system and connect to MySQL server. It will not prompt for any password.

So, here we need to secure the MySQL server. The packages provides a script to do it. Execute the following command for the initial settings of your MySQL server. You will see that script will prompt for more settings than earlier MySQL versions like password validation policy etc.

sudo mysql_secure_installation

Follow the on screen instruction to finish wizard. All the user inputs are highlighted in the wizard below. This will create password for the root user, remove test database and user to secure database server.

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component? 

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: 2
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) : y
Success.


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) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

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!

Step 3 – Manage MySQL Service

MySQL service is managed under the systemd service manager. You can follow the default systemctl commands to manage database service on command line. Below is the some frequently used commands to manage service:

  • To stop MySQL service, type:
    sudo systemctl stop mysql
    
  • To start MySQL service, type:
    sudo systemctl start mysql
    
  • Stop then start MySQL service, type:
    sudo systemctl restart mysql
    
  • To view status of MySQL service, type:
    sudo systemctl status mysql
    

Step 4 – Connect MySQL Server

You have successfully installed and secured the MySQL database server on your Ubuntu 20.04 system. Now connect to your database server on command line with the following command.

mysql -u root -p

Enter MySQL root user password to connect:

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.19-0ubuntu5 (Ubuntu)

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.

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

mysql>

Step 5 – Create MySQL User and Database

As you have connected to the MySQL server on command line. Your database server is ready to use for your applications to store data.

We recommend to create a separate database user to connect database by the application. Use the following commands to create a database on MySQL. Then create a user and assign privileges to user on database.

1
2
3
4
5
6
7
CREATE DATABASE mydb;
 
CREATE USER 'myuser'@'localhost' IDENTIFIED by 'Pa$$w0rd';
 
GRANT ALL on mydb.* to 'myuser'@'localhost';
 
FLUSH PRIVILEGES;

Conclusion

This tutorial helps you with the installation of MySQL server on Ubuntu system. It also provides instruction’s to secure database server. Next, you can install phpMyAdmin to administer MySQL server via web based interface.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

8 Comments

  1. Avatar pp Reply
    August 31, 2020 at 5:30 pm

    Thanks Rahul

  2. Avatar Lokeshwar Reply
    August 18, 2020 at 7:50 am

    How can i install Kubeflow In ubuntu do u have any tutorial for it.

  3. Avatar Paul A. Gureghian Reply
    July 29, 2020 at 10:52 pm

    I have a question about this tutorial.

    • Rahul Rahul Reply
      July 30, 2020 at 7:59 am

      Yes, please

      • Avatar Paul A. Gureghian Reply
        July 30, 2020 at 6:29 pm

        ‘secret’ did not work, but ‘Pa$$w0rd’ did. when creating a user.

        • Avatar İbrahim Alper SÖNMEZ Reply
          December 8, 2020 at 8:09 am

          Because there is a plugin called “validate_password” and by default it rejects passwords that are:
          – shorter then 8 characters
          – without at least 1 number
          – without at least 1 upper case character
          – without at least 1 special character

          You can list it’s settings with:
          sudo mysql
          SHOW VARIABLES LIKE ‘validate_password%’;

          If you set them as belows:
          SET GLOBAL validate_password.length=5;
          SET GLOBAL validate_password.number_count=0;
          SET GLOBAL validate_password.mixed_case_count=0;
          SET GLOBAL validate_password.special_char_count=0;

          …only then it will accept ‘secret’ as a valid password.

  4. Avatar Vladimir Reply
    May 6, 2020 at 9:08 pm

    Hello,

    How I can install MySQL 5? This is very important to me for using Magento 1 version.

    Thank you.

    • Rahul Rahul Reply
      May 8, 2020 at 4:05 pm

      Currently Ubuntu 20.04 default repository or MySQL official apt repository doesn’t contains packages of MySQL 5.7. We will update you once the packages are available.

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Ubuntu 20.04 5
  • How To Install Python 3.9 on Ubuntu 18.04 0
  • How to Use AppImage on Linux (Beginner Guide) 2
  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy