How to install MYSQL on Linux?

How to install MYSQL on Linux?

Share Now
4 min read

MySql is an open-source database management system. It provides tables and fields for storing necessary information. Let’s see How to Install MYSQL on Linux?

Before we start, let us make sure that the Underlying Ubuntu Server is updated with its latest update. Run the below command on the server.

Now, once the Ubuntu server is up and running with the latest updates, now it’s time to install MySQL on Linux.

apt install mysql-server

You need to agree to use the space by pressing “Y”

You may ignore that by pressing “Enter” Or you may set the Mysql root user password on this screen. We can do that later anyway.

I think, if you ignore this during installation, the splash screen will come 3 times to input a password.

Now, run the below command to secure your MySQL database.


This will come up with few questions and that would expect you to Press “Y/n”

It’s up to each individual, based on your need, you can proceed with the right selection.

Let me put all the questions here So that you know what are they.

Question 1: This will ask if you want to Set a Root Password for your MySQL database.

I have selected “n” so it skipped.

Question 2: This will ask if you want to remove the anonymous user.

Question 3: Disable remote root login.

The remaining Questions are below.

Now, your MySQL is installed on Ubuntu. To verify that execute the below command.

Run the command (1) MySQL

You will get a blinking line with (2) mysql>

Few basic Queries:

1. To list all the databases.

mysql> show databases;

2. To use any database from above.

mysql> use mysql; ( use database_name)

3. To see the list of tables

mysql> show tables;

4. List the fields of any table, I use these two ways. There could be others, please comment and let me know.

mysql> describe user;

mysql> select * from user limit 1;

Delete Table/Database.

Check the user got a password or not.

You can see, the user “root” does not have any password.

Now, To set a password for the root user you can use the below command.

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');


ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass’; ( I think this is for the latest versions )

To check if the user got any password, you can execute the below command.

mysql> select user,password,host,authentication_string from user where user='root';

Now, from next time, when you log in to the SQL server locally.

Most importantly you have to use the below command to log in

MySQL -u root -p;

To get more ideas about My SQL  and understand How to install MYSQL on Linux?  follow us Lia Infraservices

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Leave comment

Your email address will not be published. Required fields are marked with *.