To deploy a specific version of the MySQL database on an ECS instance with the Linux operating system, you can follow the steps outlined in this topic to manually complete the MySQL database deployment.
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 inbound rule for the security group associated with the ECS instance permits traffic through port 22. For detailed instructions, see Add Security Group Rules.
Deploy MySQL
Alibaba Cloud Linux 3
-
Remotely connect to the ECS instance. For detailed instructions, see Logging on to a Linux instance using the Workbench tool over SSH.
-
Install the MySQL database.
NoteTo install MySQL version 8.0, change the official repository URL to
https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm
.# Install compat-openssl10 to be compatible with the old version of the OpenSSL library. sudo yum install -y compat-openssl10 # Add the official MySQL source sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el8-1.noarch.rpm # Install MySQL sudo dnf install -y mysql-server # Start MySQL and configure MySQL to automatically start on system startup sudo systemctl start mysqld sudo systemctl enable mysqld
-
Retrieve the default initial password for the root user.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)
-
Launch the MySQL secure installation wizard.
sudo mysql_secure_installation
-
Enter the initial password for the
root
user.NotePassword characters are hidden during entry. Ensure accuracy when typing.
-
The root password has expired. You must set a new password for the
root
user and enter it twice for confirmation.ImportantThe password must include at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least eight characters long.
After you change the
root
password, enter n to decline resetting the password.-
Enter 'y' to remove the anonymous user.
NoteRemoving the anonymous user helps prevent unauthorized access to your MySQL server by users without valid credentials.
-
Enter y to disable remote logon for the MySQL
root
user.NoteIf you need to allow the
root
user remote access, press any key other thanY
to enable remote root logon. Enter 'y' to remove the default
test
database included with MySQL.Enter 'y' to reload the privilege tables and ensure that all changes are applied.
-
Alibaba Cloud Linux 2
-
Remotely connect to the ECS instance. For detailed instructions, see Logging on to a Linux instance using the Workbench tool over SSH.
-
Install the MySQL database.
NoteTo install MySQL version 8.0, change the official source address to
https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
.# Add the official MySQL source sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm # Install MySQL sudo yum install -y mysql-server # Start MySQL and configure MySQL to automatically start on system startup sudo systemctl start mysqld sudo systemctl enable mysqld
-
Retrieve the default initial password for the root user.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)
-
Launch the MySQL secure installation wizard.
sudo mysql_secure_installation
-
Enter the initial password for the
root
user.NotePassword characters are hidden during entry. Ensure accuracy when typing.
-
The root password has expired. You must set a new password for the
root
user and enter it twice for confirmation.ImportantThe password must include at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least eight characters long.
After you change the
root
password, enter n to decline resetting the password.-
Enter 'y' to remove the anonymous user.
NoteRemoving the anonymous user helps prevent unauthorized access to your MySQL server by users without valid credentials.
-
Enter y to disable remote logon for the MySQL
root
user.NoteIf you need to allow the
root
user remote access, press any key other thanY
to enable remote root logon. Enter 'y' to remove the default
test
database included with MySQL.Enter 'y' to reload the privilege tables and ensure that all changes are applied.
-
CentOS 8
-
Remotely connect to the ECS instance. For detailed instructions, see Logging on to a Linux instance using the Workbench tool via SSH.
-
Install the MySQL database.
NoteTo install MySQL version 8.0, change the official repository URL to
https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm
.# Add the official MySQL source sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el8-1.noarch.rpm # Install MySQL sudo dnf install -y mysql-server # Start MySQL and configure MySQL to automatically start on system startup sudo systemctl start mysqld sudo systemctl enable mysqld
-
Launch the MySQL secure installation wizard.
sudo mysql_secure_installation
-
Enter 'y' to enable the
VALIDATE PASSWORD
component. -
Select 2 to enforce a password policy requiring at least one uppercase letter, one lowercase letter, one digit, one special character, and a minimum length of eight characters.
-
You must set a new password for the
root
user and enter it twice for confirmation.ImportantThe password must include at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least eight characters long.
-
Enter y to confirm the use of the provided password.
-
Enter 'y' to remove the anonymous user.
NoteRemoving the anonymous user helps prevent unauthorized access to your MySQL server by users without valid credentials.
-
Enter y to disable remote logon for the MySQL
root
user.NoteIf you need to allow the
root
user remote access, press any key other thanY
to enable remote root logon. Enter 'y' to remove the default
test
database included with MySQL.Enter 'y' to reload the privilege tables and ensure that all changes are applied.
-
CentOS 7
-
Remotely connect to the ECS instance. For detailed instructions, see how to log on to a Linux instance using the Workbench tool over SSH.
-
Install the MySQL database.
NoteTo install MySQL version 8.0, change the official source address to
https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
.# Add the official MySQL source sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm # Install MySQL sudo yum install -y mysql-server # Start MySQL and configure MySQL to automatically start on system startup sudo systemctl start mysqld sudo systemctl enable mysqld
-
Retrieve the default initial password for the root user.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)
-
Launch the MySQL secure installation wizard.
sudo mysql_secure_installation
-
Enter the initial password for the
root
user.NotePassword characters are hidden during entry. Ensure accuracy when typing.
-
The root password has expired. You must set a new password for the
root
user and enter it twice for confirmation.ImportantThe password must include at least one uppercase letter, one lowercase letter, one digit, one special character, and be at least eight characters long.
After you change the
root
password, enter n to decline resetting the password.-
Enter 'y' to remove the anonymous user.
NoteRemoving the anonymous user helps prevent unauthorized access to your MySQL server by users without valid credentials.
-
Enter y to disable remote logon for the MySQL
root
user.NoteIf you need to allow the
root
user remote access, press any key other thanY
to enable remote root logon. Enter 'y' to remove the default
test
database included with MySQL.Enter 'y' to reload the privilege tables and ensure that all changes are applied.
-
Ubuntu/Debian
-
Connect to the ECS instance remotely. For specific operations, see Log on to a Linux instance by using the Workbench tool over SSH.
-
Run the following commands to update the system APT repository and ensure the system package list is current.
sudo apt-get update
-
Install 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 # Use the dpkg command to install the downloaded MySQL APT configuration package sudo dpkg -i mysql-apt-config_0.8.33-1_all.deb
-
(Optional) If the mysql-apt-config script detects that your operating system version is not officially supported, it will display an interface that allows you to select the option closest to your system version to continue the installation.
NoteFor more information, see the FAQ about deploying MySQL.
-
The configuration page lists all components to be installed, including MySQL Server, Client, Tool, and a series of components. Confirm that the version and components to be installed are correct, switch to
OK
with the arrow keys, and press Enter.
-
-
Install the MySQL server.
ImportantDuring the installation, when setting the password for the
root
user of MySQL, you must follow the password policy: The password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character, and the total length must be at least eight characters. Enter your password and press Enter to confirm. Enter it twice to complete the setup.# 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 # Automatically start on system startup sudo systemctl enable mysql
-
Run the command to start the MySQL secure installation wizard.
sudo mysql_secure_installation
-
Enter the password of the
root
user. -
Enter 'y' to enable the
VALIDATE PASSWORD
component. -
Select 2 to enforce a password policy requiring at least one uppercase letter, one lowercase letter, one digit, one special character, and a minimum length of eight characters.
-
Enter n to reject changing the root user password.
NoteIf you need to change the
root
user password, you can entery
to make the change. -
Enter 'y' to remove the anonymous user.
NoteRemoving the anonymous user helps prevent unauthorized access to your MySQL server by users without valid credentials.
-
Enter y to disable remote logon for the MySQL
root
user.NoteIf you need to allow the
root
user remote access, press any key other thanY
to enable remote root logon. Enter 'y' to remove the default
test
database included with MySQL.Enter 'y' to reload the privilege tables and ensure that all changes are applied.
-
Add remote access MySQL user
-
Remotely connect to the ECS instance. For detailed instructions, see how to log on to a Linux instance using the Workbench tool over SSH.
-
When setting up the security group, MySQL defaults to using port 3306. Make sure the instance's security group inbound rule permits traffic on port 3306. Should you opt for an alternative port, modify the security group settings to reflect the actual port in use. For detailed instructions, see Add security group rules.
-
Create a user with remote access to all MySQL databases using the following command.
Important-
Replace
<username>
with the username you created for the MySQL user in the code. -
Replace
<password>
in the code with the password you created for the MySQL user. Ensure the password adheres to the policy: It should include at least one uppercase letter, one lowercase letter, one digit, and one special character, with a minimum length of eight characters.
# You need to enter the root user password after execution sudo mysql -uroot -p \ -e "CREATE USER '<username>'@'%' IDENTIFIED BY '<password>';" \ -e "GRANT ALL PRIVILEGES ON *.* TO '<username>'@'%' WITH GRANT OPTION;" \ -e "FLUSH PRIVILEGES;"
-
-
Test the effectiveness of the configured username and password.
# <username> is the username of the newly created user. You need to enter the password of your new user after execution sudo mysql -u<username> -p
References
For more information, see the FAQ on MySQL deployment.