MySQL installation in Ubuntu Linux 18.04 LTS

MySQL is an open source and popular RDMS 
(Relational Database Management System). It’s widely used in web technology in today’s date, and also it’s part of LAMP (Linux, Apache, MySQL, PHP/Perl/Python) stack. 

In this post, we will demonstrate “two methods” to install MySQL database in Ubuntu Linux 18.04 LTS. Following are the two methods. We will walk you through one by one.

  1. Using Ubuntu repository
  2. MySQL Official repository
Read Also: 

Installation of Ubuntu 18.04 LTS Server.


1. Installed Ubuntu 18.04 LTS Server
2. root or Sudo access
3. Internet access 
Method 1: Using Ubuntu repository.
This method is very straight forward, execute below commands after fulfilling above Pre-requisites.

$ sudo apt update

$ sudo apt install mysql-server
$  sudo mysqladmin -p -u root version
As seen above, MySQL is installed bit older version.
Remove MySQL from the system.
$ sudo apt remove mysql-server
What about when you want to installed the latest version of MySQL? Follow the steps below.
Method 2: MySQL Official Repository
Step 1: Download MySQL Community Edition APT Repository from below link and install the downloaded repository.
Step 2: Install the downloaded repository with below command. This will open package configuration windows and click on “OK“.
$ sudo dpkg -i mysql-apt-config_0.8.14-1_all.deb
Step 3: Update repositories
$ sudo apt update
Step 4: Install MySQL using same command which we have used in Ubuntu Repository steps. This will again open package configuration windows to set authentication plugin.
$ sudo apt install mysql-server -y
Package Configuration windows to set authentication plugin. Select “OK” with arrow key and press <ENTER> to accept. It will start installation of MySQL database.
Check mysql service should be running
$ sudo systemctl status mysql.service
Step 5:Check MySQL version after installation.
$ sudo mysqladmin -p -u root version
Step 6:Securing MySQL
$ sudo mysql_secure_installation
This will ask some sets of security questions as follows:
1. Would you like to setup VALIDATE PASSWORD component =Y
2. Password valid policy, choose 2 for = Strong
3. Set root password = <pwd>
4. Remove anonymous user = Y
5. Dissallow root login remotely = Y
6. Remove test database and access to it. Y
7. Reload privilege tables now  = Y
Step 7: Login in MySQL Shell, enter user password (not mysql root) and verify authentication_string and plugin with command below.
$  sudo mysql
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
Step 8: We will execute ALTER command to configure the root account to authenticate with password. Make sure to choose strong password. Check below authentication methods that root is no longer authenticates using the auth_socket plugin after executing below ALTER command.
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘Password@1234’;
Step 9: Now login with root user and password which we have set in Step 8.
That’s it. In this article, we have installed MySQL in Ubuntu 18.04 LTS Linux using two methods. Share your experience through comment box below. Please share it with others and follow us on our Facebook Official Page.

0 thoughts on “MySQL installation in Ubuntu Linux 18.04 LTS”

Leave a Comment