How to install MYSQL in UBUNTU?

Divey Anand
3 min readSep 9, 2023

--

My LINUX Version is UBUNTU 22.02 and I want to install Mysql to connect with JAVA.

When I started my journey to install MYSQL , I faced few querries which i tried to write in this blog for me and there are some questions in my mind also. May be it will help the community as well.

During the installation in UBUNTU , I have to download 2 things i.e MYSQL server and MYSQL Workbench.

Q1. Why do we need 2 installations separately?

MySQL Server and MySQL Workbench are two different products. MySQL Server is a database server, while MySQL Workbench is a graphical user interface (GUI) tool for working with MySQL databases.

MySQL Server is required to store and manage data in a MySQL database. It is a standalone product that can be installed on any computer. MySQL Workbench is not required to use MySQL Server. It is a GUI tool that can be used to connect to a MySQL Server, create and manage databases, and develop and execute SQL queries.

Let’s start MYSQL installation:

Step 1. Open terminal in UBUNTU. Ctrl + Alt + T

Type :

1

sudo apt update

Step 2:

1

sudo apt install mysql-server

Step 3: Once installation is done run this command to enter into MYSQL

But I faced error after installation as below:

You might also face this error as well:

To resolve this error, I found below solution, so you might need it so do the same.

If you want to go in root folder use this command :

sudo -i

Then type the below command

dpkg --get-selections | grep mysql (to get the version of MySQL)

dpkg-reconfigure mysql-server-8.0

mysql -u root -p

Then enter Password, but I was not able to resolve still 🙂

So now finally type this solution:

sudo cat /etc/mysql/debian.cnf

Note down password for client user as we are going to login with it.

mysql -u debian-sys-maint -p

Type the above password shared by your UBUNTU System.

Now you are in MYSQL server, so change the password for root user: (Check only the last command)

SET PASSWORD FOR ‘root’@’localhost’ = ‘sa12345’;

Now as we have setup , MYSQL server, I want my MYSQL worbench:

Go to this link https://dev.mysql.com/downloads/ and go to below download section and select the UBUNTU version and download the same.

You will receive the MYSQL Workbench in application.

--

--