How to install MySQL in Linux(CentOS/Ubuntu).

We will learn about how to install MySQL in Linux, we will look at the installation step by step in CentOS 7, CentOS 8, and Ubuntu distributors.

MySQL is the Relation Database, which is used to store the data. It Is open-source and widely used in the industries.

First, we will download the MySQL installer of any distributors as per your requirement.

So, after using that link you can select the Installer of your choice and will get the download link.

Just right click on “Download” and select “Copy link address” and we will move to our Terminal.

So, now we will install wget in CentOS 7/8 and Ubuntu to download the MySQL Packages.

In CentOS:

# yum install wget

In Ubuntu:

# apt install wget

Let’s Find the Quick View to Install MySQL in Linux.

But after the QUICK view come and read the POST to get Detail knowledge about the installation of MySQL in Linux.

Click on Quick view to Install Mysql on CentOS

Step 1: Download the Package of MySQL in CentOS 7 and CentOS 8.

In CentOS 7:

# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar

In CentOSĀ 8:

# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.19-1.el8.x86_64.rpm-bundle.tar

STEP 2: Extract the Package of MySQL in CentOS 7 and CentOS 8.

In CentOS 7:

# tar -xvf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar

In CentOS 8:

# tar -xvf mysql-8.0.19-1.el8.x86_64.rpm-bundle.tar

STEP 3: Install the Package of MySQL.

In CentOS 7/8:

# yum install perl-Data-Dumper perl-JSON openssl-devel -y
# rpm -vih *.rpm

STEP 4: Start the service of MySQL.

In CentOS 7/8:

# systemctl start mysqld
# systemctl enable mysqld

STEP 5: Configure MySQL with “mysql_secure_installation”.

In CentOS 7/8:

# mysql_secure_installation

STEP 6: Logged in and Check the Database of MySQL in CentOS 7/8.

# mysql -h localhost -u[username] -p[password]

Click on Quick view to Install Mysql on Ubuntu

STEP 1: Download the Package of MySQL in Ubuntu 18/19

In Ubuntu 18

$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_8.0.19-1ubuntu18.04_amd64.deb-bundle.tar

In Ubuntu 19

$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_8.0.19-1ubuntu19.10_amd64.deb-bundle.tar

STEP 2: Extract the Package of MySQL

In Ubuntu 18

# tar -xvf mysql-server_8.0.19-1ubuntu18.04_amd64.deb-bundle.tar

In Ubuntu 19

# tar -xvf mysql-server_8.0.19-1ubuntu19.10_amd64.deb-bundle.tar

STEP 3: Install the Package of MySQL using dpkg command.

$ sudo dpkg -i *.deb
$ sudo apt-get install -f

STEP 4: Logged in and Check the Database of MySQL in Ubuntu.

$ mysql -h localhost -u[username] -p[password]

Click to Jump on the Detailed Installation of MySQL in Ubuntu 18 and Ubuntu 19.

So, let’s install MySQL 8 on CentOS 7 and CentOS 8 Step by Step

STEP 1: Download the Package of MySQL in CentOS 7 and CentOS 8.

In CentOS 7

# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar

In CentOS 8

# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.19-1.el8.x86_64.rpm-bundle.tar

So, the file has been downloaded as “mysql-8.0.19.X.X.rpm-bundle.tar” and next, we have to extract the file using tar command.

STEP 2: Extract the Package of MySQL in CentOS 7 and CentOS 8.

In CentOS 7

# tar -xvf  mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar

In CentOS 8

# tar -xvf  mysql-8.0.19-1.el8.x86_64.rpm-bundle.tar

So, after extraction let’s install the packages using rpm command.

STEP 3: Install the Package of MySQL using rpm command.

In CentOS 7/8

So, before installing we got some dependencies error.

Let’s install the dependencies into CentOS 7 and CentOS 8

# yum install perl-Data-Dumper perl-JSON openssl-devel -y

And then use rpm command to install the MySQL Package in CentOS7/8.

# rpm -vih *.rpm

STEP 4: Start the service of MySQL in CentOS 7/8.

# systemctl start mysqld

Start the service using systemctl command and if we want to start the service at the time of booting use below command.

# systemctl enable mysqld
STEP 5: Configure MySQL in CentOS 7/8.

So, after that check, the “mysqld.log” in /var/log/ folder, were you will get the temporary password.

# cat /var/log/mysqld.log

We can see the logs very clearly the logs, let’s set our own password using “mysql_secure_installation”

[root@tla ~]# mysql_secure_installation

So, you can “Enter a password of your choice” but there is some policy in MySQL for the password.

  1. The password length should be 8 or more than that.
  2. There should be one special character like “@#$!”
  3. There should be one UPPER case letter.
  4. Finally, there should be one LOWER case letter.

So then it will ask to remove the anonymous user press “y” to remove.

Next, it will prompt to Disallow root login remotely? means if we want to login from the root user remotely, press y|Y or press any other key to No.

So after that, it will ask to remove the test database and reload the changes and that’s Done.

So we have successfully install and configured the MySQL.

STEP 6: Logged in and Check the Database of MySQL in CentOS 7/8.

So to log in, we have kept the password as “Tastethelinux@123” with the username as “root”.

# mysql -h localhost -uroot -pTastethelinux@123

Let’s check the database after login, use “>show databases”

mysql> show databases;

So, let’s install MySQL 8 on Ubuntu Step by Step

STEP 1: Download the Package of MySQL in Ubuntu 18/19

In Ubuntu 18

$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_8.0.19-1ubuntu18.04_amd64.deb-bundle.tar

In Ubuntu 19

$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_8.0.19-1ubuntu19.10_amd64.deb-bundle.tar

STEP 2: Extract the Package of MySQL in Ubuntu 18/19

In Ubuntu 18

# tar -xvf mysql-server_8.0.19-1ubuntu18.04_amd64.deb-bundle.tar

In Ubuntu 19

# tar -xvf mysql-server_8.0.19-1ubuntu19.10_amd64.deb-bundle.tar

STEP 3: Install the Package of MySQL using dpkg command.

$ sudo dpkg -i *.deb

Before installing we got some of the dependencies error

$ sudo apt-get install -f

So, let’s install the dependencies by using above command

STEP 4: Logged in and Check the Database of MySQL in Ubuntu.

So. let’s login into Database using mysql command

So, you can see the version and username and password is the root we have set in Step 3.

$ mysql -h localhost -uroot -proot

After we will check the database by show databases command.

mysql>show databases;

Detail about the Installation of MySQL in CentOS 7 and CentOS 8.

Install MySQL in Linux any version you can refer this POST.