Tutorials How to Install MySQL on Ubuntu Linux

How to Install MySQL on Ubuntu Linux

MySQL is considered the most popular database management system in the world. It is an open-source database management system which is usually installed as part of LAMP stack. For managing the data, it uses a relational database and structured query language (SQL). Here I am going to describe the steps of how to install MySQL on an Ubuntu server.

Requirements


Before going to install MySQL on Ubuntu, it is advised to have the latest version of Ubuntu server with the necessary setup. This setup includes a non-root user having sudo privileges and a firewall.

Installation Process


  • MySQL Installation

In the latest versions of Ubuntu, MySQL is available by default in the APT package repository. For a successful installation process, updating the package index on the server is essential with “apt.”

sudo apt update

After that complete the installation of the default package.

sudo apt-get install mysql-server

By this, MySQL will be installed. But, setting password and configuration modification is not allowed due to security purposes.

  • MySQL Configuring

During a fresh installation, if you run the included security script, it will change some default options of less security for the purposes like sample users and remote root logins. In the latest versions of MySQL, the data directory is initialized automatically whereas older versions needed a manual initiation.

sudo mysql_secure_installation

It will drive you through a sequence where you can bring necessary changes to the security options of MySQL installation. The first prompt will inquire that whether you want to set up any password plugin to examine the strength of MySQL password given by you. The second prompt will ask you to set up a password dedicated to the MySQL root user. Confirm the selected password from here.

Then, pressing “Y” and “ENTER” will accept the defaults for all situations. Anonymous users and test database will be removed by this. This will also disable remote root login and activate the new rules changed by you for immediate action by MySQL.

For initializing the MySQL data directory, use “mysql_install_db” command for previous versions of 5.7.6 and for the versions after that use “mysqld –initialize.” If MySQL is installed from the Debian distribution, data directory is initialized by default. No additional action required.

It is to be mentioned that, setting a password for the root MySQL user does not ensure that the user has authentication with a password for connecting to MySQL shell. If required, following step 3 you can adjust this setting.

  • Adjustment of User Authentication and Privileges (Optional)

No password but a default plugin “auth_socket” is used to authenticate the root MySQL user in Ubuntu systems running the latest versions of MySQL (5.7 and later). Though it permits for some greater security and ease of use, in some cases like allowing an external program to access the user, it may create a complicated scenario.

For using a password to as root to MySQL, it is needed to change the authentication method. This change of authentication is form “auth_socket” to “mysql_native_password.” From the terminal, open up MySQL prompt to perform this action.

sudo mysql

After that, with the following command check the user authentication method of your MySQL user account.

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

Adjustment of User Authentication and Privileges

In the above example, it is seen that using the “auth_socket” plugin; the root user complete the authentication process. For configuring the root account to authenticate using a password, the following “ALTER USER” command is to run. Select a strong password and mind it that the root password set up in step 2 will be changed with this command.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Then, run the following command to reload the grant tables and putting new changes into effect.

mysql> FLUSH PRIVILEGES;

Check the authentication methods assigned by each user to be assured that root does not authenticate using “auth_socket” plugin.

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

authentication methods assigned by each user

In this example, you can see that the authentication is done by root MySQL user by using a password. Once confirmed on the server, you can exit the shell.

mysql> exit

Now, is the time to test the MySQL installation.

  • Testing the MySQL Installation

No matter how you have installed MySQL, it should have initiated functioning automatically. With the following command, check its status.

sudo systemctl status mysql.service

Testing the MySQL Installation

You can initiate with:

sudo systemctl start mysql

If MySQL does not run. You can try in another way of connecting to the database utilizing “mysqladmin” tool for an additional check. It is a client which allows run the administrative commands.

sudo mysqladmin -p -u root version

It indicates that MySQL is up and running.

Concluding Words


Now, MySQL is installed on your Ubuntu server. For ease of use, you can now modify it. Besides, adding measures is also possible for enhancing security. Is this tutorial on how to install MySQL on Ubuntu helpful? If you like it, please take a moment to share this tutorial on your social network. And don’t forget to leave your suggestion and experience in the comment section.

LATEST POST

Best Disk Cloning Software for Linux

Top 15 Best Disk Cloning Software for Linux in 2019

No matter whether you're a professional sysadmin like me or just an average Linux maniac, you must understand the importance of regularly backing up...
Applications of Machine Learning in Healthcare

Top 10 Potential Applications of Machine Learning in Healthcare

With the rapid growth of the population, it seems challenging to record and analyze the massive amount of information about patients. Machine learning provides...
Use VPN Services In Linux

How To Set Up A VPN With Linux: A Comprehensive Beginner’s Guide

A VPN or a Virtual Private Network basically means creating a secured private network using public infrastructure. This process helps create a protected network...

MOST COMMENTED

Linux or Windows: 25 Things You Must Know While Choosing The Best Platform

Linux or Windows: 25 Things You Must Know While Choosing The Best Platform

Choosing the best platform - Linux or Windows is complicated. Because both the system is versatile and capable of doing many mission-oriented and regular...
Most Stable Linux Distros

Most Stable Linux Distros: 5 versions of Linux We Recommend

At the very beginning, I would like to mention why the term ‘Stable’ comes in relation to Linux OS or distro. Because there are...
Best Things To Do After Installing Linux Mint

15 Best Things To Do After Installing Linux Mint 19 “Tara”

Linux Mint is one of the best Linux distros for newcomers, especially who comes from other Operating Systems like Windows and MacOS. Linux Mint...

Hand-Picked Related Post

LEAVE A REPLY

Please enter your comment!
Please enter your name here