This topic shows you how to manually install a specific version of MySQL on a Linux-based Elastic Compute Service (ECS) instancex.
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.
The security group for the instance must allow inbound traffic on port 22. For instructions, see Add a security group rule.
Deploy MySQL
Alibaba Cloud Linux 3
Connect to an ECS instance. For more information, see Connect to Linux.
Install MySQL.
# 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 mysqldRetrieve the temporary root password.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)Run the secure installation script.
sudo mysql_secure_installationEnter the temporary password for the
rootuser.NoteThe password is not displayed as you type. Ensure you enter it correctly.

The root password has expired. The system prompts you to set a new password for the
rootuser. Re-enter the password to confirm.ImportantThe password policy requires the password to contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long.

When asked if you want to change the password again, enter
n.
Enter
yto remove anonymous users.NoteRemoving anonymous users helps prevent unauthorized access to your MySQL server.

Enter
yto disallow remote root login.NoteTo allow remote root login, press any key other than
Y.
Enter
yto remove thetestdatabase.
Enter
yto reload the privilege tables to apply your changes.
Alibaba Cloud Linux 2
Connect to an ECS instance. For more information, see Connect to Linux.
Install MySQL.
# 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 mysqldRetrieve the temporary root password.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)Run the secure installation script.
sudo mysql_secure_installationEnter the temporary password for the
rootuser.NoteThe password is not displayed as you type. Ensure you enter it correctly.

The root password has expired. The system prompts you to set a new password for the
rootuser. Re-enter the password to confirm.ImportantThe password policy requires the password to contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long.

When asked if you want to change the password again, enter
n.
Enter
yto remove anonymous users.NoteRemoving anonymous users helps prevent unauthorized access to your MySQL server.

Enter
yto disallow remote root login.NoteTo allow remote root login, press any key other than
Y.
Enter
yto remove thetestdatabase.
Enter
yto reload the privilege tables to apply your changes.
CentOS 8
Connect to an ECS instance. For more information, see Connect to Linux.
Install MySQL.
# 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 secure installation script.
sudo mysql_secure_installationEnter
yto use theVALIDATE PASSWORDcomponent.
Enter
2to set the password validation policy toSTRONG. This policy requires passwords to contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long.
Set a new password for the
rootuser and enter it twice to confirm.ImportantThe password must meet the requirements of the validation policy you selected.

Enter
yto continue with the password you provided.
Enter
yto remove anonymous users.NoteRemoving anonymous users helps prevent unauthorized access to your MySQL server.

Enter
yto disallow remote root login.NoteTo allow remote root login, press any key other than
Y.
Enter
yto remove thetestdatabase.
Enter
yto reload the privilege tables to apply your changes.
CentOS 7
Connect to an ECS instance. For more information, see Connect to Linux.
Install MySQL.
# 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 mysqldRetrieve the temporary root password.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)Run the secure installation script.
sudo mysql_secure_installationEnter the temporary password for the
rootuser.NoteThe password is not displayed as you type. Ensure you enter it correctly.

The root password has expired. The system prompts you to set a new password for the
rootuser. Re-enter the password to confirm.ImportantThe password policy requires the password to contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long.

When asked if you want to change the password again, enter
n.
Enter
yto remove anonymous users.NoteRemoving anonymous users helps prevent unauthorized access to your MySQL server.

Enter
yto disallow remote root login.NoteTo allow remote root login, press any key other than
Y.
Enter
yto remove thetestdatabase.
Enter
yto reload the privilege tables to apply your changes.
Ubuntu or Debian
Connect to an ECS instance. For more information, see Connect to Linux.
Update your system's package index.
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
mysql-apt-configdetects an unsupported OS version, an interface appears. Select the closest supported version to continue the installation.NoteTo find your system's codename, see What do I do if I cannot start MySQL due to the "Permission denied" error?

The configuration page lists all components to be installed. Verify that the correct version and components are selected, then use the arrow keys to navigate to
Okand press Enter.
Install the MySQL server.
ImportantDuring the installation, you must set a password for the MySQL
rootuser. The password policy requires the password to contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long. Enter the password and press Enter. You must re-enter it to confirm.

# 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 secure installation script.
sudo mysql_secure_installationEnter the
rootuser password you set during installation.
Enter
yto use theVALIDATE PASSWORDcomponent.
Enter
2to set the password validation policy toSTRONG. This policy requires passwords to contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long.
Enter n to skip changing the password of the root user.
NoteTo change the password of the
rootuser, entery.
Enter
yto remove anonymous users.NoteRemoving anonymous users helps prevent unauthorized access to your MySQL server.

Enter
yto disallow remote root login.NoteTo allow remote root login, press any key other than
Y.
Enter
yto remove thetestdatabase.
Enter
yto reload the privilege tables to apply your changes.
Add a MySQL user for remote access
Connect to an ECS instance. For more information, see Connect to Linux.
By default, MySQL listens on port 3306. Ensure the instance's security group allows inbound traffic on port 3306. If you use a different port, adjust the security group rules accordingly. For instructions, see Add a security group rule.
Run the following command to create a user who can connect from any host and grant the user privileges on all databases.
ImportantReplace
<username>with the new username.Replace
<password>with the password for the new user. The password must contain at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least 8 characters long.
# 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;"Verify the connection with the new user's credentials.
# 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