3 diciembre, 2024

Instalar MySQL 8.0/5.7 en Fedora 31/30/29/28/27, CentOS/RHEL 7.5/6.9

Guía para instalar MariaDB 10.2/10.1/10.3

MySQL es un Sistema Manejador de Bases de Datos  Relacionales – Relational Database Management System (RDBMS) que corre como un servidor dando acceso multiusuario y a  varias bases de datos.

Con esta guía ser instalará o actualizará MySQL Community Server a su última versión 5.7 (5.7.22) / 8.0 (8.0.11)  en Fedora 31/30/29/28/27, CentOS/RHEL 7.5/6.9

Esta guía trabaja con Oracle Linux y Scientific Linux tambíen.

Importante: Si estás actualizando MySQL (desde una versión anterior), entonces asegurate que tengas los respaldos y copias de tu base de datos y de la configuración. Recuerda correl el comando mysql_upgrade

Instalar MySQL Database 5.7.22/8.0.11 on Fedora 31/30/29/28/27/26, CentOS 7.5/6.9, Red Hat (RHEL) 7.5/6.9

1. Cambiate al usuario root

su -
## OR ##
sudo -i

2. Instala los repositorios YUM de MySQL

Fedora

## Fedora 31 ##
dnf install https://dev.mysql.com/get/mysql80-community-release-fc31-1.noarch.rpm

## Fedora 30 ##
dnf install https://dev.mysql.com/get/mysql80-community-release-fc30-1.noarch.rpm

## Fedora 29 ##
dnf install https://dev.mysql.com/get/mysql80-community-release-fc29-1.noarch.rpm

## Fedora 28 ##
dnf install https://dev.mysql.com/get/mysql80-community-release-fc28-1.noarch.rpm

## Fedora 27 ##
dnf install https://dev.mysql.com/get/mysql80-community-release-fc27-1.noarch.rpm

## Fedora 26 ##
dnf install https://dev.mysql.com/get/mysql80-community-release-fc26-1.noarch.rpm

CentOS and Red Hat (RHEL)

## CentOS 7 and Red Hat (RHEL) 7 ##
yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

## CentOS 6 and Red Hat (RHEL) 6 ##
yum localinstall https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm

3a. Actualiza o instala MySQL 8.0.11

Fedora 31/30/29/28/27/26

dnf install mysql-community-server

o

dnf update mysql-community-server

CentOS 7.5/6.9 and Red Hat (RHEL) 7.5/6.9

yum install mysql-community-server

o

yum update mysql-community-server


3b. Actualiza o instala MySQL 5.7.22

Fedora 31/30/29/28/27/26

dnf --disablerepo=mysql80-community --enablerepo=mysql57-community install mysql-community-server

CentOS 7.5/6.9 and Red Hat (RHEL) 7.5/6.9

yum --disablerepo=mysql80-community --enablerepo=mysql57-community install mysql-community-server

4. Arranca MySQL server y realizar ejecución automática de MySQL al bootear

Fedora 31/30/29/28/27/26 and CentOS 7.5 and Red Hat (RHEL) 7.5

systemctl start mysqld.service ## use restart after update

systemctl enable mysqld.service

CentOS 6.9 and Red Hat (RHEL) 6.9

/etc/init.d/mysql start ## use restart after update
## OR ##
service mysql start ## use restart after update

chkconfig --levels 235 mysqld on

5. Generar un password aleatorio para root

grep 'Un password temporal es generado para root@localhost' /var/log/mysqld.log |tail -1



Example Output:



2015-11-20T21:11:44.229891Z 1 [Note] Un password temporal es generado para root@localhost: -et)QoL4MLid



And root password is: -et)QoL4MLid


6. Instalación segura de MySQL

  • Change root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database and access to it
  • Reload privilege tables

Empezar una instalación segura para MySQL con el siguiente comando:

/usr/bin/mysql_secure_installation

Salida:

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 

VALIDATE PASSWORD PLUGIN 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 plugin?

Press y|Y for Yes, any other key for No: y

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: 0
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) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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
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
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
 - 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
Success.

All done! 

Importante: Sin no quieres, por alguna razón , realizar la instalación Segura de MySQL, entonces, por lo menos, es importante cambiar el password de root con los siguientes comandos

mysqladmin -u root password [your_password_here]

## Example ##
mysqladmin -u root password myownsecrectpass

7. Conectar al Sistema Manejador de bases de datos MySQL mediante (localhost) pidiendo un password para acceder

mysql -u root -p

## OR ##
mysql -h localhost -u root -p

8. Crear una base de datos en MySQL y permitir una conexión a la base de datos creada

El siguiente ejemplo usa los siguientes parametros:

  • DB_NAME = webdb
  • USER_NAME = webdb_user
  • REMOTE_IP = 10.0.15.25
  • PASSWORD = password123
  • PERMISSIONS = ALL
## CREATE DATABASE ##
mysql> CREATE DATABASE webdb;

## CREATE USER ##
mysql> CREATE USER 'webdb_user'@'10.0.15.25' IDENTIFIED BY 'password123';

## GRANT PERMISSIONS ##
mysql> GRANT ALL ON webdb.* TO 'webdb_user'@'10.0.15.25';

##  FLUSH PRIVILEGES, Tell the server to reload the grant tables  ##
mysql> FLUSH PRIVILEGES;

Enable Remote Connection to MariaDB Server –> Open MySQL Port (3306) on Iptables Firewall (as root user again)


1. Fedora 31/30/29/28/27/26 and CentOS/Red Hat (RHEL) 7.5

1.1 Agregar una regla nueva al Firewalld

firewall-cmd --permanent --zone=public --add-service=mysql

## OR ##

firewall-cmd --permanent --zone=public --add-port=3306/tcp

1.2 Resetear el servicio firewalld.service

systemctl restart firewalld.service

2. CentOS/Red Hat (RHEL) 6.9

2.1 Editar el archivo /etc/sysconfig/iptables :

nano -w /etc/sysconfig/iptables

2.2 Agregar el siguiente regla INPUT:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

2.3 Restart Iptables Firewall:

service iptables restart
## OR ##
/etc/init.d/iptables restart


3. Test remote connection

mysql -h 10.0.15.25 -u myusername -p


Fuente: https://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/



Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *