How to Install MySQL on Ubuntu 21.04 / 20.04

In the realm of modern technology, data plays a pivotal role in numerous applications and systems. Efficiently managing and organizing this data is crucial for businesses and developers alike. This is where MySQL comes into the picture – it is a widely adopted relational database management system (RDBMS).

MySQL is an open-source RDBMS that offers a robust, scalable, and reliable platform for storing, retrieving, and managing structured data. It encompasses a wide array of features, such as support for multiple data types, high-performance query execution, data integrity and security mechanisms, and exceptional scalability options.

From small-scale web applications to large enterprise systems, MySQL has emerged as the go-to choice for developers, businesses, and organizations across diverse industries. Its versatility, user-friendly nature, and extensive community support make it the preferred option for constructing database-driven applications. By selecting Ubuntu as your operating system for MySQL installation, you gain advantages such as a user-friendly interface, stability, security, and compatibility.

Why Should You Use Ubuntu For MySQL Installation?

When it comes to selecting an operating system for running MySQL, Ubuntu stands out as a popular choice among developers and system administrators. Ubuntu server is a Linux-based operating system renowned for its user-friendly interface, stability, security, and extensive community support. Ubuntu’s widespread usage for MySQL installation stems from these reasons:”

  • Ubuntu’s package repositories offer a vast collection of software packages, including MySQL. This makes it incredibly convenient to install and update MySQL using the built-in package manager, apt.
  • Ubuntu places a strong emphasis on security and stability, regularly providing updates and long-term support (LTS) releases. This ensures that the MySQL installation remains secure and reliable over an extended period.
  • Ubuntu boasts a large and active community of developers and users who are readily available to provide assistance and share knowledge. This community-driven support can be invaluable when troubleshooting issues or seeking guidance during the MySQL installation process.
  • Ubuntu is highly compatible with various hardware configurations and offers excellent support for both desktop and server environments. This versatility makes it suitable for a wide range of MySQL installation scenarios.

System Requirements

For Ubuntu 21.04 and 20.04, the minimum hardware specifications are as follows:

  1. CPU: 2 GHz dual-core processor or better.
  2. RAM: 2 GB or more (4 GB recommended for optimal performance).
  3. Storage: 25 GB of free disk space.
  4. Display: 1024×768 resolution or higher.

Keep in mind that these are minimum requirements, and depending on your specific use case and workload, you may need more resources to ensure smooth operation of Ubuntu and MySQL.

Installing MySQL

mysql installation
  • Open a terminal: Press Ctrl+Alt+T to open a new terminal window.
  • Download and add the MySQL APT repository package by running the following command:
wget https://dev.mysql.com/get/mysql-apt-config_0.8.19-1_all.deb
  • Install the downloaded package:
sudo dpkg -i mysql-apt-config_0.8.19-1_all.deb
  • During the installation process, you’ll be prompted to choose the MySQL product version and other repository settings. Select the desired options and press Enter to continue.

Installing MySQL Server

code to install mysql server
  • Update the package lists:
sudo apt update
  • Install the MySQL server package:
sudo apt install mysql-server
  • During the installation, you’ll be prompted to set a password for the MySQL root user. Choose a strong password, confirm it, and remember it for future use.

Securing the MySQL installation

Run the MySQL security script to improve the installation security:

sudo mysql_secure_installation

The script will prompt you to validate the password for the MySQL root user, remove anonymous users, disallow root login remotely, and remove the test database. Follow the prompts and answer “Y” to all the questions for a more secure installation.

Configuring MySQL

  • To start the MySQL service, run the following command in the terminal:
sudo systemctl start mysql
  • To stop the MySQL service, use the following command:
sudo systemctl stop mysql
  • By default, the MySQL service starts automatically during system boot. If you need to disable automatic startup, you can use the command 
sudo systemctl disable mysql
  • If you disabled automatic startup in the previous step and want to enable it again, use the following command:
sudo systemctl enable mysql

This will configure MySQL to start automatically whenever the system boots up.

Testing MySQL Installation

To check the status of the MySQL server, run the following command:

sudo systemctl status mysql

If the MySQL server is running correctly, you should see a message indicating that it is active and running. You may encounter issues, error messages, or warnings, and you will need to troubleshoot accordingly.

Accessing the MySQL command-line Interface

  • To access the MySQL command-line interface, use the following command: mysql -u root -p
  • You will be prompted to enter the password you set during the installation process. Type the password and press Enter.
  • If the password is correct, you will be greeted with the MySQL command prompt, which looks like mysql>.

Conclusion

To summarize, setting up MySQL on Ubuntu 21.04 or 20.04 is a simple process that can be achieved using either the Ubuntu package manager or the MySQL official repository. This guide provides step-by-step instructions to help you establish a strong and dependable database management system on your Ubuntu system. Thanks to its robust features and scalability options, MySQL finds widespread use in various applications and systems. Being open-source, versatile, and having a supportive community attributes to its popularity.

You can also read about how you can Install LAMP on ubuntu server.

Related Post

SSH Key vs Password Based Authentication

Authentication plays a pivotal role in upholding securi...

How to Install Cassandra on Ubuntu

Apache Cassandra is a highly scalable distributed NoSQL...

Remote MySQL in cPanel

Remote access to MySQL databases is an essential featur...

How to Run SQL Queries in phpMyAdmin

phpMyAdmin a free and open-source web application serve...

How to Install MongoDB on Windows

MongoDB, a leading NoSQL database, is a powerful and ve...

How to Install phpPgAdmin on Windows 10

phpPgAdmin is a free, web-based interface for managing ...

Leave a Comment