How to Install MySQL on Ubuntu Linux

On this occasion I will share a tutorial on installing MySQL on an Ubuntu-based Linux distribution. You will also learn how to verify installation and how to connect to MySQL for the first time.

How to Install MySQL on Ubuntu Linux

MySQL is a classic database management system. This is used in many technology stacks, including the popular LAMP (Linux, Apache, MySQL, PHP) stack. This has proven its stability. Another thing that makes MySQL so good is open-source.

How to install and use MySQL 8.0 on Ubuntu 18.04. Let's begin!

I will discuss two ways that you can install MySQL on Ubuntu 18.04 :

1). Install MySQL from the Ubuntu repository. Very basic, not the latest version (5.7)

2). Install MySQL using an official repository. There are bigger steps that you must add to the process, but there is no need to worry. You will also have the latest version (8.0)

I will enter the command in the terminal (default hotkey: CTRL + ALT + T).

Method 1. Install MySQL from the Ubuntu repository

SUDO APT UPDATE

Now, to install MySQL 5.7, just type:

SUDO APT INSTALL MYSQL-SERVER -Y

There she is! Simple and efficient.

Method 2. Install MySQL using an official repository

Although this method has a few more steps, I will discuss them one by one and I will try to write clear notes.

The first step is to browse to the official MySQL website download page.

How to Install MySQL on Ubuntu Linux

Here, open the download link for the DEB Package.

How to Install MySQL on Ubuntu Linux

Scroll down past the info about Oracle Web and right-click on No thanks, just start my download . Select Copy link location .

Now back to the terminal. We will use the Curl command to download the package :

curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb

https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb is a link that I copied from the website. It might be different based on the current MySQL version. Let's use dpkg to start installing MySQL :

sudo dpkg -i mysql-apt-config*

Update your repository:

sudo apt update

To actually install MySQL, I will use the same command as in the first method :

sudo apt install mysql-server -y

Doing so will open a prompt in your terminal for package configuration. Use the down arrow to select the Ok option.

How to Install MySQL on Ubuntu Linux

Press Enter. This will ask you to enter your password. You basically set the root password for MySQL. Don't be confused with the Ubuntu system root password.

How to Install MySQL on Ubuntu Linux

Type the password and press Tab to select . Press Enter. You must now re-enter your password. After doing so, press Tab again to select . Press Enter.

How to Install MySQL on Ubuntu Linux

Some information about MySQL Server configuration will be presented. Press Tab to select and Enter again:

How to Install MySQL on Ubuntu Linux

Here you need to choose the default authentication plugin. Make sure Use Strong Password Encryption is selected. Press Tab then Enter. You have successfully installed MySQL.

Verify the MySQL installation

To verify that MySQL is installed correctly, use :

sudo systemctl status mysql.service

How to Install MySQL on Ubuntu Linux

You will see Active: active (running) there somewhere. If not, use the following command to start the service:

sudo systemctl start mysql.service

For new installs, you must run the command provided for security-related updates:

sudo mysql_secure_installation

First of all, you will be asked if you want to use VALIDATE PASSWORD COMPONENTS. If you want to use it, you must choose a minimum password strength (0 - Low, 1 - Medium, 2 - High). You will not be able to enter any password that does not comply with the rules chosen.

If you are not used to using strong passwords, this can be useful. If you think that can help, type y or Y and press Enter, then select the strength level for your password and enter what you want to use. If successful, you will continue the security process, if not, you will have to re-enter the password.

However, if you don't want this feature (I don't want to), just press Enter or another button to skip using it.

For other options, I recommend activating them (typing y or Y and pressing Enter for each). They (in this order): delete anonymous users, ban remote logins remotely, delete test databases and access to them, reload current privilege tables.

Menghubungkan ke dan Memutuskan dari Server MySQL

To be able to run SQL queries, you must first connect to the server using MySQL and use the MySQL prompt. The command to do this is:

mysql -h host_name -u user -p

-h is used to determine the hostname (if the server is located on another computer; if not, just ignore it)

-u mentioned the user

-p specifies that you want to enter a password.

Although not recommended (for security reasons), you can enter the password directly in the command by typing it right after -p.

For example, if the password for test_user is 1234 and you try to connect to the machine you are using, you can use:

mysql -u test_user -p1234

If you successfully enter the required parameters, you will be greeted by the MySQL shell prompt (mysql>):

How to Install MySQL on Ubuntu Linux

To disconnect from the server and leave the mysql prompt, type:

QUIT

Typing stops (MySQL is not case sensitive) or q will also work. Press Enter to exit.

You can also display info about the version with a simple command:

sudo mysqladmin -u root version -p

If you want to see a list of options, use:

mysql –help

If you want to uninstall MySQL

If you decide to use a newer release or just want to stop using MySQL.

First, deactivate the service:

sudo systemctl stop mysql.service && sudo systemctl disable mysql.service

Make sure you back up your database, if you want to use it later. You can uninstall MySQL by running:

sudo apt purge mysql*

To clear cache:

sudo apt autoremove

In this article, I have discussed installing MySQL on Ubuntu Linux. May be useful.

Post a Comment

Previous Post Next Post