Updated on 2023-10-19 GMT+08:00

Installing a MySQL Database (Community Edition)

This section describes how to initialize disks and install a MySQL database (community edition).

Log In to the ECS

  1. Log in to the management console.
  2. Click in the upper left corner of the management console and select EU-Dublin.
  3. Under the service list, choose Compute > Elastic Cloud Server.
  4. Locate the ECS ecs-mysql and click Remote Login in the Operation column.
  5. Select CloudShell-based Login.

  6. Enter the password of user root.

    The password is the one you specified during the ECS creation.

Initializing Disks

  1. Create the mysql folder.

    mkdir /mysql

  2. View data disk information.

    fdisk -l

    The command output is as follows.

  3. Initialize the data disk.

    mkfs.ext4 /dev/vdb

  4. Attach the disk.

    mount /dev/vdb /mysql

  5. Check whether the disk is attached.

    df -h

    If the following output is returned, the disk is attached.

  6. Create a folder and switch to the install folder.

    mkdir -p /mysql/install/data

    mkdir -p /mysql/install/tmp

    mkdir -p /mysql/install/file

    mkdir -p /mysql/install/log

    cd /mysql/install

  7. Download and install How Can I Install the MySQL Client?
  8. Initialize the MySQL client.

    /mysql/install/mysql-8.0.22/bin/mysqld --defaults-file= /etc/my.cnf --initialize-insecure

  9. Start the MySQL client.

    nohup /mysql/install/mysql-8.0.22/bin/mysqld --defaults-file= /etc/my.cnf &

  10. Connect to the MySQL client.

    /mysql/install/mysql-8.0.22/bin/mysql

  11. Create user root and assign the required permissions to it.

    grant all privileges on *.* to 'root'@'%' identified by 'xxx' with grant option;FLUSH PRIVILEGES;