Install MySQL on Ubuntu 18.04 | 20.04

Install MySQL on Ubuntu 18.04 20.04

This post shows users and new students that how to Install MySQL on Ubuntu 18.04 | 20.04. If your are going to Install MySQL on Ubuntu 18.04 | 20.04 then this post is ideal for you.

MySQL is a non-profit(free) and open-source database management system that uses SQL(Structured Query Language). It is Fast and Secure relational database management system.

MySQL is open source, so if you want you can change its source code according to your need without paying a single money.

For more information about MySQL database, please check its official website.

Let’s start the Installing MySQL on Ubuntu, simply follow the below steps to installing latest version of MySQL :

Installing MySQL on Ubuntu

MySQL packages comes with the Ubuntu repositories. So you just need to run the below commands for install the MySQL server.

sudo apt update
sudo apt install mysql-server

With the above command, MySQL server installed in your Ubuntu machine.

Now, run the below commands to start, stop and restart the MySQL services.

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl restart mysql.service

For check the server status, simply run the below command :

sudo systemctl status mysql.service

The above command show the result similar like below.

mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-04-30 09:04:02 CDT; 5s ago
Process: 4222 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, stat>
Main PID: 4248 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 4657)
Memory: 376.8M
CGroup: /system.slice/mysql.service
└─4248 /usr/sbin/mysqld
Apr 30 09:04:01 ubuntu2004 systemd[1]: Starting MySQL Community Server…
Apr 30 09:04:02 ubuntu2004 systemd[1]: Started MySQL Community Server.

In the MySQL server you can enhance its security by secure the root user with password and by removing other insecure things.

Simply run the below command to secure MySQL Server:

sudo mysql_secure_installation

When you run the above command, it will prompt you with some questions. Follow the below instruction to complete the setup.

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! 

In above step, you setup a password for Root User. If you want or wish that you will be granted access without required a password then simply run the below command for do that.

sudo mysql

The above command automatically will granted access.

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
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>

This above step happens because Current version comes with auth_socket plugin that is provides root authentication.

This plugin creates issues with some applications who requires to connect with the database via root. To fix this problem or issue, you need to change default authentication process from auth_socket to mysql_native_password.

For do that, login back into the MySQL console.

sudo mysql

Now run the below commands for change to mysql_native_password.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Your_Password';

Replace Your_Password with password that you want to use.

Then save your changes and exit:

FLUSH PRIVILEGES;
EXIT;

whenever if you want to access MySQL console then you will be prompted for type password.

If you don’t want to use MySQL root user to connect external application then you should create a separate admin account from the root user. Simply run the below command to do that.

GRANT ALL PRIVILEGES ON *.* TO 'superadmin'@'localhost' IDENTIFIED BY 'very_strong_password';

Install MySQL from its Offical Repository

For Install MySQL from its Official Repository, you need to add its repository.

The below link is take you its download page :

https://dev.mysql.com/downloads/repo/apt/

when above link is opened, simply click on Download button for get repository packages.

Install MySQL Ubuntu

Run the commands below:

cd /tmp
wget https://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.16-1_all.deb

Now, Simply select OK button when you get a configuration prompt.

After installed repository, run the below commands to install :

sudo apt update
sudo apt upgrade

That’s all

If you find any error and issue in above steps , please use comment box below to report.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top