Este tema describe cómo desplegar manualmente una versión específica de una base de datos MySQL en una instancia ECS con Linux.
Requisitos previos
La instancia ECS debe tener asignada automáticamente una dirección IP pública. Como alternativa, puede asociar una dirección IP elástica (EIP) a la instancia ECS. Para obtener instrucciones sobre cómo habilitar el ancho de banda público, consulte Enable public bandwidth.
El security group de la instancia ECS debe contar con una regla de entrada que permita el tráfico en el puerto 22. Para más información, consulte Add a security group rule.
Despliegue de MySQL
Alibaba Cloud Linux 3
Conéctese a la instancia ECS. Para más información, consulte Log on to a Linux instance using Workbench.
-
Instale la base de datos MySQL.
# Install compat-openssl10 for compatibility with older OpenSSL libraries. sudo yum install -y compat-openssl10 # Add the official MySQL repository. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el8-1.noarch.rpm # Install the MySQL service. sudo dnf install -y mysql-server # Start the MySQL service and enable it to start on boot. sudo systemctl start mysqld sudo systemctl enable mysqld -
Obtenga la contraseña temporal de root.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD) -
Ejecute el siguiente comando para iniciar el asistente de instalación segura de MySQL.
sudo mysql_secure_installation-
Introduzca la contraseña temporal del usuario
root.NotaLa contraseña no se muestra mientras la escribe. Asegúrese de introducirla correctamente.
Securing the MySQL server deployment. Enter password for user root: -
Cuando el sistema indique que la contraseña de root ha caducado, establezca una nueva contraseña para el usuario
root. Debe introducir la nueva contraseña dos veces.ImportanteLa política de contraseñas exige una longitud mínima de 8 caracteres y debe contener como mínimo una letra mayúscula, una minúscula, un dígito y un carácter especial.
The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: -
Después de cambiar la contraseña de
root, introduzca n para omitir el cambio de contraseña.Change the password for root ? (Press y|Y for Yes, any other key for No) : -
En el indicador
Remove anonymous users?, introduzca y.NotaEliminar usuarios anónimos ayuda a prevenir el acceso al servidor MySQL sin una cuenta de usuario.
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : -
En el indicador
Disallow root login remotely?, introduzca y para prohibir el inicio de sesión remoto del usuariorootde MySQL.NotaSi necesita permitir el inicio de sesión remoto de
rootpor algún motivo específico, presione cualquier tecla distinta deY.Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : -
En el indicador
Remove test database and access to it?, introduzca y para eliminar la base de datostestpredeterminada.By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : -
En el indicador
Reload privilege tables now?, introduzca y para aplicar los cambios.Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
-
Alibaba Cloud Linux 2
Conéctese a la instancia ECS. Para más información, consulte Log on to a Linux instance using Workbench.
-
Instale la base de datos MySQL.
# Add the official MySQL repository. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm # Install the MySQL service. sudo yum install -y mysql-server # Start the MySQL service and enable it to start on boot. sudo systemctl start mysqld sudo systemctl enable mysqld -
Obtenga la contraseña temporal de root.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD) -
Ejecute el siguiente comando para iniciar el asistente de instalación segura de MySQL.
sudo mysql_secure_installation-
Introduzca la contraseña temporal del usuario
root.NotaLa contraseña no se muestra mientras la escribe. Asegúrese de introducirla correctamente.
Securing the MySQL server deployment. Enter password for user root: -
Cuando el sistema indique que la contraseña de root ha caducado, establezca una nueva contraseña para el usuario
root. Debe introducir la nueva contraseña dos veces.ImportanteLa política de contraseñas exige una longitud mínima de 8 caracteres y debe contener como mínimo una letra mayúscula, una minúscula, un dígito y un carácter especial.
The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: -
Después de cambiar la contraseña de
root, introduzca n para omitir el cambio de contraseña.Change the password for root ? (Press y|Y for Yes, any other key for No) : -
En el indicador
Remove anonymous users?, introduzca y.NotaEliminar usuarios anónimos ayuda a prevenir el acceso al servidor MySQL sin una cuenta de usuario.
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : -
En el indicador
Disallow root login remotely?, introduzca y para prohibir el inicio de sesión remoto del usuariorootde MySQL.NotaSi necesita permitir el inicio de sesión remoto de
rootpor algún motivo específico, presione cualquier tecla distinta deY.Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : -
En el indicador
Remove test database and access to it?, introduzca y para eliminar la base de datostestpredeterminada.By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : -
En el indicador
Reload privilege tables now?, introduzca y para aplicar los cambios.Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
-
CentOS 8
Conéctese a la instancia ECS. Para más información, consulte Log on to a Linux instance using Workbench.
-
Instale la base de datos MySQL.
# Add the official MySQL repository. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el8-1.noarch.rpm # Install the MySQL service. sudo dnf install -y mysql-server # Start the MySQL service and enable it to start on boot. sudo systemctl start mysqld sudo systemctl enable mysqld -
Ejecute el siguiente comando para iniciar el asistente de instalación segura de MySQL.
sudo mysql_secure_installation-
En el indicador
Would you like to setup VALIDATE PASSWORD component?, introduzca y para habilitar el componenteVALIDATE PASSWORD.Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: -
Introduzca 2 para establecer el nivel de política de contraseñas en
STRONG. Esta política requiere que las contraseñas tengan como mínimo 8 caracteres, contengan números, letras mayúsculas y minúsculas, caracteres especiales y no se basen en un archivo de diccionario.There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: -
Establezca una nueva contraseña para el usuario
root. Debe introducir la nueva contraseña dos veces.New password: Re-enter new password: Estimated strength of the password: 100ImportanteLa política de contraseñas exige una longitud mínima de 8 caracteres y debe contener como mínimo una letra mayúscula, una minúscula, un dígito y un carácter especial.
-
En el indicador
Do you wish to continue with the password provided?, introduzca y.Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : -
En el indicador
Remove anonymous users?, introduzca y.NotaEliminar usuarios anónimos ayuda a prevenir el acceso al servidor MySQL sin una cuenta de usuario.
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : -
En el indicador
Disallow root login remotely?, introduzca y para prohibir el inicio de sesión remoto del usuariorootde MySQL.NotaSi necesita permitir el inicio de sesión remoto de
rootpor algún motivo específico, presione cualquier tecla distinta deY.Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : -
En el indicador
Remove test database and access to it?, introduzca y para eliminar la base de datostestpredeterminada.By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : -
En el indicador
Reload privilege tables now?, introduzca y para aplicar los cambios.Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
-
CentOS 7
Conéctese a la instancia ECS. Para más información, consulte Log on to a Linux instance using Workbench.
-
Instale la base de datos MySQL.
# Add the official MySQL repository. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm # Install the MySQL service. sudo yum install -y mysql-server # Start the MySQL service and enable it to start on boot. sudo systemctl start mysqld sudo systemctl enable mysqld -
Obtenga la contraseña temporal de root.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD) -
Ejecute el siguiente comando para iniciar el asistente de instalación segura de MySQL.
sudo mysql_secure_installation-
Introduzca la contraseña temporal del usuario
root.NotaLa contraseña no se muestra mientras la escribe. Asegúrese de introducirla correctamente.
Securing the MySQL server deployment. Enter password for user root: -
Cuando el sistema indique que la contraseña de root ha caducado, establezca una nueva contraseña para el usuario
root. Debe introducir la nueva contraseña dos veces.ImportanteLa política de contraseñas exige una longitud mínima de 8 caracteres y debe contener como mínimo una letra mayúscula, una minúscula, un dígito y un carácter especial.
The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: -
Después de cambiar la contraseña de
root, introduzca n para omitir el cambio de contraseña.Change the password for root ? (Press y|Y for Yes, any other key for No) : -
En el indicador
Remove anonymous users?, introduzca y.NotaEliminar usuarios anónimos ayuda a prevenir el acceso al servidor MySQL sin una cuenta de usuario.
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : -
En el indicador
Disallow root login remotely?, introduzca y para prohibir el inicio de sesión remoto del usuariorootde MySQL.NotaSi necesita permitir el inicio de sesión remoto de
rootpor algún motivo específico, presione cualquier tecla distinta deY.Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : -
En el indicador
Remove test database and access to it?, introduzca y para eliminar la base de datostestpredeterminada.By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : -
En el indicador
Reload privilege tables now?, introduzca y para aplicar los cambios.Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
-
Ubuntu/Debian
Conéctese a la instancia ECS. Para más información, consulte Log on to a Linux instance using Workbench.
-
Ejecute el siguiente comando para actualizar la lista de paquetes.
sudo apt-get update -
Instale el repositorio APT de MySQL.
# 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-
(Opcional) Si el script
mysql-apt-configdetecta que la versión de su sistema operativo no es compatible oficialmente, aparecerá una interfaz. Seleccione la versión compatible más adecuada para continuar.NotaPara encontrar el nombre en clave de su sistema, consulte FAQ.
Configuring mysql-apt-config The detected system (ubuntu bionic) is not supported by MySQL. If you believe the platform is compatible with one of the supported systems, one of the corresponding repositories may be selected. Add repository to unsupported system? ubuntu lunar ubuntu focal ubuntu jammy ubuntu noble ubuntu oracular debian bookworm abort <Ok> -
La página de configuración enumera todos los componentes que se instalarán, incluidos MySQL Server, Client y Tools. Compruebe la versión y los componentes, use las teclas de flecha para navegar hasta
Oky presione Enter.Configuring mysql-apt-config The MySQL APT Repository features MySQL Server along with a variety of components. You may select the desired products to install and update from the official MySQL Repository, and also select the associated version series. Select "Ok" to save the configuration, and then execute "apt update" to load the selected package list. This configuration can be updated later, depending on your needs. Which MySQL product do you wish to configure? MySQL Server & Cluster (Currently selected: mysql-8.4-lts) MySQL Connectors (Currently selected: Enabled) Ok <Ok>
-
-
Instale el servidor MySQL.
ImportanteDurante la instalación, el cuadro de diálogo Configuring mysql-community-server le solicitará establecer una contraseña para el usuario
rootde MySQL. La política de contraseñas exige una longitud mínima de 8 caracteres y debe incluir una letra mayúscula, una minúscula, un dígito y un carácter especial. En el campo Enter root password, introduzca su contraseña y seleccione Ok. En el siguiente cuadro de diálogo Configuring mysql-community-server, vuelva a introducir la contraseña en el campo Re-enter root password y seleccione Ok para confirmar. Si deja el campo de contraseña en blanco, se habilitará la autenticación mediante socket UNIX. Mantenga esta contraseña segura.# 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 service status. sudo systemctl status mysql # Enable the service to start on boot. sudo systemctl enable mysql -
Ejecute el siguiente comando para iniciar el asistente de instalación segura de MySQL.
sudo mysql_secure_installationIntroduzca la contraseña del usuario
root.-
En el indicador
Would you like to setup VALIDATE PASSWORD component?, introduzca y para habilitar el componenteVALIDATE PASSWORD.Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: -
Introduzca 2 para establecer el nivel de política de contraseñas en
STRONG. Esta política requiere que las contraseñas tengan como mínimo 8 caracteres, contengan números, letras mayúsculas y minúsculas, caracteres especiales y no se basen en un archivo de diccionario.There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: -
Dado que estableció la contraseña de root durante el paso de instalación con apt, puede omitir el cambio ahora. Introduzca n para continuar.
NotaSi necesita cambiar la contraseña del usuario
root, introduzcay. -
En el indicador
Remove anonymous users?, introduzca y.NotaEliminar usuarios anónimos ayuda a prevenir el acceso al servidor MySQL sin una cuenta de usuario.
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : -
En el indicador
Disallow root login remotely?, introduzca y para prohibir el inicio de sesión remoto del usuariorootde MySQL.NotaSi necesita permitir el inicio de sesión remoto de
rootpor algún motivo específico, presione cualquier tecla distinta deY.Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : -
En el indicador
Remove test database and access to it?, introduzca y para eliminar la base de datostestpredeterminada.By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : -
En el indicador
Reload privilege tables now?, introduzca y para aplicar los cambios.Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
Adición de un usuario remoto de MySQL
Conéctese a la instancia ECS. Para más información, consulte Log on to a Linux instance using Workbench.
Asegúrese de que el security group de la instancia tenga una regla de entrada que permita el tráfico en el puerto 3306. Si utiliza un puerto diferente, ajuste la configuración del security group en consecuencia. Para más información, consulte Add a security group rule.
-
Ejecute el siguiente comando para crear un usuario y otorgar permisos de acceso remoto a todas las bases de datos MySQL.
ImportanteReemplace
<username>con el nombre de usuario que desea crear.Reemplace
<password>con la contraseña del usuario de MySQL. La contraseña debe tener como mínimo 8 caracteres e incluir una letra mayúscula, una minúscula, un dígito y un carácter especial.
# After you run the command, enter the password for 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;" -
Compruebe la conexión utilizando las credenciales del nuevo usuario.
# Replace with the username of the user that you created. After you run the command, enter the password for the new user. sudo mysql -u<username> -p