Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks

How to install MySQL in Ubuntu?

Aman Jain, September 18, 2021September 18, 2021

MySQL is a most popular and open source relational database. it provides multi user support with a many storage engines. in this tutorial we are going to install MySQL in Ubuntu.

Let’s begin with simple steps:

Step 1 : Open terminal in Ubuntu and install MySQL package

Here, we are going to install the MySQL using the terminal. Open terminal by pressing Ctrl+Alt+T or ssh into server

sudo apt-get install mysql-server

 This will install the MySQL server and won’t ask you to set the password so let’s move to the next step of securing the MySQL server.

2.2. Securing MySQL server

After the fresh installation of MySQL, we are going to secure our MySQL by strengthening the password, type of authentication and root password.

sudo mysql_secure_installation

The above command will ask many questions as below

2.2.1 Do you want to Validate password plugin

Securing the MySQL server deployment

Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:

Press Any key for no for now.

2.2.2 Set root password for MySQL

Next prompt will be set root password .

Please set the password for root here.

New password:
Re-enter new password:

Enter the password twice and move to next step.

2.2.3 Remove Anonymous Users

Next question would be for removing Anonymous user.

Remove anonymous users? (Press y|Y for Yes, any other key for No) 

Enter Y and go ahead.

2.2.3 Disable Remote Root Login

By default, MySQL comes with a database named ‘test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :

Enter Y and go ahead.

2.2.4 Reload Privilege Tables

Reloading privileges to ensure that all changes will take effect.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

Enter Y and go ahead.

2.2.5 Check MySQL Service

sudo service mysql status
Screenshot 2021 09 17 at 2.15.59 PM

2.2.6 Login into MySQL terminal

sudo mysql -u root -p 

Enter password and you will be in to mysql session.

Create a user in MySQL

Login into MySQL and enter below commnad

CREATE USER 'test'@'localhost' IDENTIFIED BY 'newpassword';

test is the username, localhost is name of server and newpassword is password for new user.

Flush privileges so new user reflect in users table of MySQL.

FLUSH PRIVILEGES;

Grant permissions to new user

GRANT SELECT ON * . * TO 'test'@'localhost';

Here *.* means we are assigning all the permissions to user test. First * denotes the databases so we can use the database name and second * denotes the permission for the database so lets change it to database level.

GRANT ALL PRIVILEGES ON `testdb` . * TO 'test'@'localhost';

Login using the new user rather then root

mysql -u test -p

Now you will be logined as test user.

Related

Devops Mysql Ubuntu

Post navigation

Previous post
Next post

Related Posts

Mysql Mysql insert select

Mastering MySQL Insert-Select: Simplify Data Manipulation Efforts

July 4, 2023March 16, 2024

In the world of database management systems, MySQL Insert Select is fastest tool to imports data from one table to another. MySQL has emerged as one of the most popular choices due to its reliability, performance, and ease of use. One of the powerful features it offers is the ability…

Read More
Devops Copy command in ubuntu

Copy command in Ubuntu

October 31, 2021October 31, 2021

Copy is very command in Ubuntu terminal. whenever we want to copy the directories or files copy command come in to the action. In this article we will lean to copy the directory, copy files, copy with hidden files, copy recursively, copy multiple files, copy with backup, copy interactively. So,…

Read More
Ubuntu How to Reset Root Password of MySQL 8 in Ubuntu 20.04

How to Reset Root Password of MySQL 8 in Ubuntu 20.04 ?

June 1, 2022June 1, 2022

Sometimes we forget or mistakenly type wrong password during the installation of mysql, So in this article i will help you to Reset Root Password of MySQL in Ubuntu 20.04. Mysql 8 has several new features and also it has change the default password algorithm for saving the password. Mysql…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • Understanding High Vulnerabilities: A Closer Look at the Week of July 14, 2025
  • Exploring Fresh Resources for Web Designers and Developers
  • The Intersection of Security and Technology: Understanding Vulnerabilities
  • Mapping Together: The Vibrant Spirit of OpenStreetMap Japan
  • Understanding High Vulnerabilities: A Deep Dive into the Weekly Summary
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version