MySQL es un sistema de administración de bases de datos gratuito y de código abierto, comúnmente utilizado en aplicaciones web para almacenar y recuperar registros e información.
MySQL fue desarrollado inicialmente por MYSQL AB, ahora propiedad de Oracle Corporation. Era la principal aplicación de base de datos para el sistema operativo Linux hasta que entró en escena MariaDB, una bifurcación de MySQL.
En este artículo, veremos cómo instalar MySQL 8.0/5.7 en CentOS 7 / RHEL 7.
Añadir repositorio MySQL
MySQL ya no se distribuye a través de los repositorios del sistema operativo. Por lo tanto, deberá agregar un repositorio oficial de MySQL para instalar el servidor de la comunidad MySQL.
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rpm
Asegúrese de que el repositorio de MySQL se haya agregado y habilitado con el siguiente comando.
yum repolist all | grep mysql | grep enabled
Salida:puede parecer.
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 221 mysql-tools-community/x86_64 MySQL Tools Community enabled: 135 mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 301
Instalar servidor comunitario MySQL
Oracle actualmente ofrece ambas versiones estables (v8.0 y v5.7). Puede elegir el que desea instalar en su máquina.
Instalar MySQL 8.0
Use el comando yum para instalar el servidor comunitario MySQL 8.0.
yum install -y mysql-community-server
Instalar MySQL 5.7
Si desea probar la versión anterior de MySQL, instale MySQL 5.7 en su máquina con el siguiente comando.
yum install -y mysql-community-server --disablerepo=mysql80-community --enablerepo=mysql57-community
Después de la instalación de MySQL, puede iniciar el servidor MySQL usando el siguiente comando.
systemctl start mysqld
Luego, habilite el servicio MySQL para que se inicie automáticamente al iniciar el sistema.
systemctl enable mysqld
Finalmente, verifique si el servidor MySQL se inicia usando el siguiente comando.
systemctl status mysqld
Contraseña raíz inicial de MySQL
En CentOS/RHEL, puede encontrar la contraseña raíz inicial de MySQL en /var/log/mysqld.log
. Puede usar el siguiente comando para tomar la contraseña del archivo de registro.
cat /var/log/mysqld.log | grep -i 'temporary password'
Salida:
2021-11-27T08:27:27.063799Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PJyCjhTjP1:n
Servidor MySQL seguro
Ahora, debe ejecutar mysql_secure_installation
para asegurar su instalación de MySQL. Este comando se encarga de establecer la contraseña de root, eliminar usuarios anónimos, deshabilitar el inicio de sesión de root de forma remota, etc.
mysql_secure_installation
Salida:
Securing the MySQL server deployment. Enter password for user root: << Enter the initital MySQL root password The existing password for the user account root has expired. Please set a new password. New password: << Enter new MySQL root password Re-enter new password: << Re-enter new MySQL root password The 'validate_password' component is installed on the server. The subsequent steps will run with the existing configuration of the component. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : N << Type N as we have already set new password ... skipping. 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) : Y << Type Y to remove anonymous users Success. 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) : Y << Type Y to disallow root login remotely Success. 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) : Y << Type Y to remove test database - Dropping test database... Success. - Removing privileges on test database... Success. 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) : Y << Type Y to reload privilege tables Success. All done!
Trabajar con el servidor MySQL
Inicie sesión en el servidor MySQL con el usuario root y su contraseña.
mysql -u root -p
Salida:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.27 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Instalar phpMyAdmin
phpMyAdmin es una herramienta de administración basada en web de código abierto para administrar bases de datos MySQL y MariaDB. Siga el siguiente enlace para instalar y configurar phpMyAdmin según su sistema operativo.
LEER:Instalar phpMyAdmin en CentOS 7/RHEL 7
Conclusión
Eso es todo. Espero que haya aprendido a instalar MySQL 8.0/5.7 en CentOS 7/RHEL 7.