All Products
Search
Document Center

:Install and configure a MySQL database

Last Updated:Jan 27, 2026

This topic describes how to install and configure a MySQL database in a Linux environment.

Procedure

  1. Log on to the Linux server terminal.

    Note

    This topic uses Ubuntu 18.04 as an example. The steps may vary for other Linux distributions.

  2. Update the software repository and install wget.

    sudo apt update

    sudo apt install wget

  3. Download the MySQL installation package.

    wget https://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb -y

    Note

    If wget is not installed, run apt install wget to install it.

  4. Update the software repository using the .deb package.

    sudo dpkg -i mysql-apt-config_0.8.16-1_all.deb

    In the dialog box that appears, select MySQL Server & Cluster (Currently selected: mysql-5.7), and then select Ok.

    install_mysql_01

  5. Query all versions of the software package that can be installed.

    sudo apt update

    sudo apt-cache policy mysql-server

    mysql-server:
      Installed: (none)
      Candidate: 5.7.32-1ubuntu18.04
      Version table:
      ...

    In the output, 5.7.32-1ubuntu18.04 is the version of the MySQL database that you can install.

  6. Install MySQL 5.7 based on the obtained version. During installation, you must set the password for the root user and keep the password confidential.

    sudo apt install -f mysql-client=5.7.32-1ubuntu18.04 mysql-community-server=5.7.32-1ubuntu18.04 mysql-server=5.7.32-1ubuntu18.04

  7. Configure the MySQL database.

    1. Configure routine security.

      sudo mysql_secure_installation

      Configure the settings as shown below:

      Enter current password for root (enter for none): <Enter password>
      VALIDATE PASSWORD PLUGIN 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 plugin? 
      
      Press y|Y for Yes, any other key for No: Y 
      
      There are three levels of password validation policy: 
      
      LOW    Length >= 8 
      MEDIUM Length >= 8, numeric, mixed case, and special characters 
      STRONG Length >= 8, numeric, mixed case, special characters and dictionary                 
      
      Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 
      Using existing password for root. 
      Estimated strength of the password: 25  
      Change the password for root ? ((Press y|Y for Yes, any other key for No) : d
      Remove anonymous users? [Y/n] Y 
      Disallow root login remotely? [Y/n] Y 
      Remove test database and access to it? [Y/n] Y 
      Reload privilege tables now? [Y/n] Y 
    2. Enable the remote access feature.

      1. Edit the MySQL database configuration file.

        sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

      2. Press the I key and change the value of bind-address to 0.0.0.0.

      3. Press the Esc key, and then enter :wq! to save the file and exit.

    3. Restart the MySQL database to make the configuration take effect.

      sudo systemctl restart mysql

  8. Check whether the MySQL database works as expected.

    1. Log on to the MySQL database as the root user.

      mysql -u root -p

    2. Query the existing database in the MySQL database console.

      show databases;

      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | mysql              |
      | performance_schema |
      | sys                |
      +--------------------+
      5 rows in set (0.00 sec)

      The preceding query result indicates that the existing MySQL database works as expected.