Updated on 2025-08-06 GMT+08:00

Deploying MySQL on an Ubuntu ECS

  1. Create an Ubuntu ECS accessible to the internet. Select VNC or SSH for remote login.

  2. Run the following commands to update the ECS image source:
    sudo apt update
    sudo apt upgrade
  3. Run the following command to install MySQL:
    sudo apt -y install mysql-server

  4. Check the MySQL status and configure it to automatically start upon ECS startup:
    sudo systemctl status mysql
    sudo systemctl enable mysql

  5. Run the following command to access MySQL:
    sudo mysql

  6. Run the following command to set the password for user root:
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'kmXNB)60Ckap';

  7. Run the following command to exit MySQL:
    exit

  8. Run the following command to harden MySQL security as required:
    mysql_secure_installation
    1. Enter the password configured in step 6.
    2. Enter y or Y if you want to configure a password policy.
    3. Set the password strength:
      • Weak password: The password contains at least eight characters.
      • Medium password: The password contains at least eight characters and consists of uppercase letters, lowercase letters, digits, and special characters.
      • Strong password: The password contains at least eight characters, consists of uppercase letters, lowercase letters, digits, and special characters, and is checked against a dictionary attack.

        0: Weak password; 1: Medium password; 2: Strong password

      Enter 2 to use a strong password.

    4. Enter y or Y for Change the password for root?.

      Enter the new password of user root. The password must meet strong password requirements.

    5. Enter y or Y for Do you wish to continue with the password provided?.
    6. Enter y or Y for Remove anonymous users?.
    7. Enter y or Y for Disallow root login remotely?.
    8. Enter y or Y for Remove test database and access to it?.
    9. Enter y or Y for Reload privilege tables now?.

  9. Run the following command to log in to the database as user root of MySQL and enter the password configured in step 8 as prompted:
    sudo mysql -u root -p

  10. Run the following command to create a database named workspace:
    CREATE DATABASE workspace;

  11. Create a user and grant the user full access to the database. In the command, workspaceuser indicates the database username, and xxxxx indicates the password of the database user. You can set them as required.
    CREATE USER 'workspaceuser'@'localhost' IDENTIFIED BY 'xxxxx';
    GRANT ALL ON workspace.* TO workspaceuser@localhost;

  12. Run the following command to update the MySQL permission table to ensure that the permissions assigned in step 11 takes effect immediately:
    FLUSH PRIVILEGES;

  13. Run the following command to exit the MySQL CLI:
    exit

  14. (Optional) Run the following commands in sequence (enter the password configured in step 11 after the first command is executed) to check whether the database and user has been created and exit the MySQL CLI:
    mysql -u workspaceuser -p
    SHOW DATABASES;
    exit