Home Linux 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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Post

50 Useful and Simple IPtables Rules for Linux Administrator

One of the main reasons behind the immense popularity enjoyed by Linux is its sheer prowess in networking. Linux...

Linux Shell Roundup: 15 Most Popular Open Source Linux Shells

Unix systems have captivated the world since its inception in the 70s. One of the fundamental features that helped...

Top 20 Most Remarkable IoT Applications in Today’s World

In the nearest future, probably we are going to live in a world with connected devices — the curiosity...

Top 20 Best Python IDE for Linux. Some of Them are Open Source

Python is a programming language. User can apply it for general purposes to design program from the backend web...

Top 20 Funny Steam Games For Kids To Play Right Now

There are ample of funny steam games for kids available on the store for the Linux system. A couple...

Most Talked Post

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...

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...

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...

Linux Mint vs Ubuntu: 15 Facts To Know Before Choosing The Best One

Ubuntu and Linux Mint are two popular Linux distros available in the Linux community. Ubuntu is a derivative of...

Top 5 Best Lightweight Linux Distros To Boost Up Your Old Computer

So here comes the million dollar question, why does anyone use Lightweight Linux distros? While all the modern Linux...

Editors' Pick

Top 15 Online Linux Terminal Emulators and Bash Editors

Online Linux Terminal or emulator is the best way...

Top 15 Linux Data Recovery Tools: The Professionals’ Choice

Sometimes you may need to access essential data saved...

Top 20+ Best AI and Machine Learning Courses in 2019

It's 2019 here, and as always we're getting a...

Linux Text Editor: 20 Text and HTML Editors Reviewed for Linux Nerds

From jotting down your latest thoughts to writing your...

Best 5 Linux Distros for Developers and Programmers

The question may come into our mind that why...