How to install MySQL on Linux?

QuestionsQuestions8 SkillsInstallation of MySQLJul, 25 2024
0365

Installing MySQL on Linux

Installing MySQL on a Linux operating system is a straightforward process, and there are several methods to do so. In this guide, we will cover the steps to install MySQL on the two most popular Linux distributions: Ubuntu and CentOS.

Installing MySQL on Ubuntu

  1. Update the Package Index:
    Before installing MySQL, it's a good idea to update the package index to ensure you have the latest package information. Open the terminal and run the following command:

    sudo apt-get update
  2. Install MySQL:
    You can install the latest version of MySQL using the following command:

    sudo apt-get install mysql-server

    This will install the MySQL server package and its dependencies.

  3. Secure the MySQL Installation:
    After the installation is complete, it's recommended to secure your MySQL installation by running the following command:

    sudo mysql_secure_installation

    This script will guide you through setting a root password, removing anonymous users, disabling remote root login, and removing the test database.

  4. Verify the MySQL Installation:
    To verify that MySQL is installed and running correctly, you can try to connect to the MySQL server using the following command:

    sudo mysql -u root -p

    This will prompt you to enter the root password you set during the secure installation process. If you can connect to the MySQL server, the installation was successful.

Installing MySQL on CentOS

  1. Install the MySQL Repository:
    On CentOS, you'll need to install the MySQL repository before you can install the MySQL server. You can do this by running the following command:

    sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
  2. Install MySQL:
    Once the repository is installed, you can install the MySQL server package using the following command:

    sudo yum install mysql-server
  3. Start the MySQL Service:
    After the installation is complete, start the MySQL service with the following command:

    sudo systemctl start mysqld
  4. Secure the MySQL Installation:
    Similar to the Ubuntu installation, you can secure your MySQL installation by running the following command:

    sudo mysql_secure_installation

    This script will guide you through setting a root password, removing anonymous users, disabling remote root login, and removing the test database.

  5. Verify the MySQL Installation:
    To verify that MySQL is installed and running correctly, you can try to connect to the MySQL server using the following command:

    sudo mysql -u root -p

    This will prompt you to enter the root password you set during the secure installation process. If you can connect to the MySQL server, the installation was successful.

In summary, installing MySQL on Linux is a straightforward process, and the steps are similar for both Ubuntu and CentOS. By following the steps outlined in this guide, you should be able to successfully install MySQL on your Linux system.

0 Comments

no data
Be the first to share your comment!