This topic describes how to manually deploy a specific version of MySQL database on an Elastic Compute Service (ECS) instance that runs Linux.
Prerequisites
A public IP address is automatically assigned to the ECS instance. Alternatively, an elastic IP address (EIP) is associated with the ECS instance. For instructions on how to enable public bandwidth, see Enable public bandwidth.
An inbound rule is added to a security group associated with the ECS instance to open port 22. For information about how to add a security group rule, see Add a security group rule.
Deploy MySQL
Alibaba Cloud Linux 3
Connect to an ECS instance. For more information, see Use Workbench to connect to a Linux instance over SSH.
Install MySQL.
NoteFor example, to install MySQL 8.0, change the repository address to
https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm.# Install compat-openssl10, which is compatible with earlier versions of OpenSSL libraries. sudo yum install -y compat-openssl10 # Add an official MySQL repository. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el8-1.noarch.rpm # Install MySQL. sudo dnf install -y mysql-server # Start and configure MySQL to automatically start on system startup. sudo systemctl start mysqld sudo systemctl enable mysqldQuery the default initial password of the root user.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)Run the following command to configure MySQL security settings:
sudo mysql_secure_installationEnter the initial password of the
rootuser.NoteThe password characters are hidden when you enter the password. Make sure that the password that you enter is correct.

If an error message indicating that the root password expired appears, specify a new password for the
rootuser by entering the new password twice.ImportantThe password must be at least eight characters in length, and contain at least one uppercase letter, one lowercase letter, one digit, and one special character.

After you change the
rootpassword, enter n to skip re-specifying a new password.
Enter y to remove the anonymous user.
NoteThis prevents unauthorized users from skipping the step of entering valid credentials and accessing your MySQL server.

Enter y to prevent the
rootuser from accessing MySQL.NoteIf you want to allow the
rootuser to connect to the MySQL server in specific scenarios, press a key other thanyto allow remote root user logons.
Enter y to remove the pre-installed
testdatabase of the MySQL server.
Enter y to reload the permissions table to allow the preceding modifications to take effect.
Alibaba Cloud Linux 2
Connect to an ECS instance. For more information, see Use Workbench to connect to a Linux instance over SSH.
Install MySQL.
NoteFor example, to install MySQL 8.0, change the repository address to
https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm.# Add an official MySQL repository. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm # Install MySQL. sudo yum install -y mysql-server # Start and configure MySQL to automatically start on system startup. sudo systemctl start mysqld sudo systemctl enable mysqldQuery the default initial password of the root user.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)Run the following command to configure MySQL security settings:
sudo mysql_secure_installationEnter the initial password of the
rootuser.NoteThe password characters are hidden when you enter the password. Make sure that the password that you enter is correct.

If an error message indicating that the root password expired appears, specify a new password for the
rootuser by entering the new password twice.ImportantThe password must be at least eight characters in length, and contain at least one uppercase letter, one lowercase letter, one digit, and one special character.

After you change the
rootpassword, enter n to skip re-specifying a new password.
Enter y to remove the anonymous user.
NoteThis prevents unauthorized users from skipping the step of entering valid credentials and accessing your MySQL server.

Enter y to prevent the
rootuser from accessing MySQL.NoteIf you want to allow the
rootuser to connect to the MySQL server in specific scenarios, press a key other thanyto allow remote root user logons.
Enter y to remove the pre-installed
testdatabase of the MySQL server.
Enter y to reload the permissions table to allow the preceding modifications to take effect.
CentOS 8
Connect to an ECS instance. For more information, see Use Workbench to connect to a Linux instance over SSH.
Install MySQL.
NoteFor example, to install MySQL 8.0, change the repository address to
https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm.# Add an official MySQL repository. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el8-1.noarch.rpm # Install MySQL. sudo dnf install -y mysql-server # Start and configure MySQL to automatically start on system startup. sudo systemctl start mysqld sudo systemctl enable mysqldRun the following command to configure MySQL security settings:
sudo mysql_secure_installationEnter y to enable the
VALIDATE PASSWORDcomponent.
Enter 2. The password must be at least eight characters in length, and contain at least one uppercase letter, one lowercase letter, one digit, and one special character.
To specify a new password for the
rootuser, enter the new password twice.ImportantThe password must be at least eight characters in length, and contain at least one uppercase letter, one lowercase letter, one digit, and one special character.

Enter y to continue using the provided password.
Enter y to remove the anonymous user.
NoteThis prevents unauthorized users from skipping the step of entering valid credentials and accessing your MySQL server.

Enter y to prevent the
rootuser from accessing MySQL.NoteIf you want to allow the
rootuser to connect to the MySQL server in specific scenarios, press a key other thanyto allow remote root user logons.
Enter y to remove the pre-installed
testdatabase of the MySQL server.
Enter y to reload the permissions table to allow the preceding modifications to take effect.
CentOS 7
Connect to an ECS instance. For more information, see Use Workbench to connect to a Linux instance over SSH.
Install MySQL.
NoteFor example, to install MySQL 8.0, change the repository address to
https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm.# Add an official MySQL repository. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm # Install MySQL. sudo yum install -y mysql-server # Start and configure MySQL to automatically start on system startup. sudo systemctl start mysqld sudo systemctl enable mysqldQuery the default initial password of the root user.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)Run the following command to configure MySQL security settings:
sudo mysql_secure_installationEnter the initial password of the
rootuser.NoteThe password characters are hidden when you enter the password. Make sure that the password that you enter is correct.

If an error message indicating that the root password expired appears, specify a new password for the
rootuser by entering the new password twice.ImportantThe password must be at least eight characters in length, and contain at least one uppercase letter, one lowercase letter, one digit, and one special character.

After you change the
rootpassword, enter n to skip re-specifying a new password.
Enter y to remove the anonymous user.
NoteThis prevents unauthorized users from skipping the step of entering valid credentials and accessing your MySQL server.

Enter y to prevent the
rootuser from accessing MySQL.NoteIf you want to allow the
rootuser to connect to the MySQL server in specific scenarios, press a key other thanyto allow remote root user logons.
Enter y to remove the pre-installed
testdatabase of the MySQL server.
Enter y to reload the permissions table to allow the preceding modifications to take effect.
Ubuntu or Debian
Connect to an ECS instance. For more information, see Use Workbench to connect to a Linux instance over SSH.
Run the following command to update the system Advanced Packaging Tool (APT) repository and ensure that the system package list is updated:
sudo apt-get updateInstall the MySQL APT repository.
# Download the APT configuration package. sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.33-1_all.deb # Run the dpkg command to install the MySQL APT configuration package that you downloaded. sudo dpkg -i mysql-apt-config_0.8.33-1_all.debOptional. If the mysql-apt-config script detects that the operating system version is not officially supported, the system prompts you to select the closest supported version to proceed with installation.
NoteFor information about how to obtain the system alias, see How do I obtain the system alias of a Ubuntu or Debian instance?

The configuration page displays all components that must be installed, such as MySQL Server, MySQL Client, and required tools. Confirm the version and components that you want to install, press the down arrow key to select
OK, and then press the Enter key.
Install the MySQL server.
ImportantDuring installation, you must follow the password policy when you specify a password for the MySQL
rootuser. The password must be at least eight characters in length, and contain at least one uppercase letter, one lowercase letter, one digit, and one special character. Enter your password twice and press the Enter key.

# Update the package list. sudo apt update # Install the MySQL server. sudo apt install -y mysql-server # Start the MySQL service. sudo systemctl start mysql # Check the startup status. sudo systemctl status mysql # Configure MySQL to automatically start on system startup. sudo systemctl enable mysqlRun the following command to configure MySQL security settings:
sudo mysql_secure_installationEnter the
rootpassword.
Enter y to enable the
VALIDATE PASSWORDcomponent.
Enter 2. The password must be at least eight characters in length, and contain at least one uppercase letter, one lowercase letter, one digit, and one special character.
Enter n to skip changing the password of the root user.
NoteTo change the password of the
rootuser, entery.
Enter y to remove the anonymous user.
NoteThis prevents unauthorized users from skipping the step of entering valid credentials and accessing your MySQL server.

Enter y to prevent the
rootuser from accessing MySQL.NoteIf you want to allow the
rootuser to connect to the MySQL server in specific scenarios, press a key other thanyto allow remote root user logons.
Enter y to remove the pre-installed
testdatabase of the MySQL server.
Enter y to reload the permissions table to allow the preceding modifications to take effect.
Add a MySQL user for remote access
Connect to an ECS instance. For more information, see Use Workbench to connect to a Linux instance over SSH.
By default, MySQL uses port 3306. Make sure that port 3306 is open in an inbound security rule of a security group associated with the instance. If you use a different MySQL port, modify the security group settings based on the actual port. For more information, see Add a security group rule.
Run the following command to create a user and grant the user access to all MySQL databases.
ImportantReplace
<username>with the username of the created MySQL user.Replace
<password>with the password you used to create the MySQL user. The password must be at least eight characters in length, and contain at least one uppercase letter, one lowercase letter, one digit, and one special character.
# After you run the command, enter the password of the root user. sudo mysql -uroot -p \ -e "CREATE USER '<username>'@'%' IDENTIFIED BY '<password>';" \ -e "GRANT ALL PRIVILEGES ON *.* TO '<username>'@'%' WITH GRANT OPTION;" \ -e "FLUSH PRIVILEGES;"Run the following command to check whether you can connect to MySQL by using the username and password of the MySQL user that you created:
# Replace <username> with the username of the user that you created. After you run the command, enter the password of the new user. sudo mysql -u<username> -p