jueves, 28 de abril de 2016

Mysql 5.7 en Centos 6.7

Fuente: https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

Podemos verificar con estos comandos

Versión de Centos
[root@localhost ~]# cat /etc/redhat-release

Arquitectura, con lo que sabremos los paquetes que debemos utilizar en 32 0 64 bits
[root@localhost ~]# uname -a

Para revisar todos los paquetes instalados
[root@localhost ~]# rpm -qa | less

1. Instalar el repositorio

[root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm

2. Revisamos los paquetes que se van a instalar

[root@localhost ~]# rpm -qa | grep mysql

la salida será así
mysql-community-libs-compat-5.7.12-1.el6.x86_64
mysql-community-libs-5.7.12-1.el6.x86_64
mysql57-community-release-el6-8.noarch
mysql-community-client-5.7.12-1.el6.x86_64
mysql-community-server-5.7.12-1.el6.x86_64
mysql-community-common-5.7.12-1.el6.x86_64

3. Revisar que este activo el repositorio de MySQL 5.7

[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"

la salida nnos indica el mysql57-community

mysql-connectors-community           MySQL Connectors Community              21
mysql-tools-community                    MySQL Tools Community                        35
mysql57-community                         MySQL 5.7 Community Server                 82

en el caso que no se tenga, podemos editar el siguiente archivo y configurar

[root@localhost ~]# nano /etc/yum.repos.d/mysql-community.repo

Revisamos que la opción de enabled este en 1

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

4. Finalmente realizamos la instalación

[root@localhost ~]# yum install mysql-community-server

Iniciamos el servicio

[root@localhost ~]# service mysqld start 

Configuramos el servicio para que se inicie automaticamente

[root@localhost ~]# chkconfig mysqld on

Podemos comprobar la versión instalada con

[root@localhost ~]# mysql --version

5. Seguridad

El comando mysql_secure_installation es importante y utilizado para la configuración del password del usurio root, remover el usuario anonymous, remover login root.

IMPORTANTE: En MySQL version 5.7 o superiores se genera un password ramdómico temporal que se encuentra en /var/log/mysqld.log.

Para poder obtenerlo usamos el siguiente comando y con este poder correo elmysql secure command.

[root@localhost ~]#  grep 'temporary password' /var/log/mysqld.log

Con esto podemos ya correr el comando y continuar con la asignación del password para el usuario root.

[root@localhost ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
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

 ... 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
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!

Para comprobar accedemos a MySQL

[root@localhost ~]# mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.7.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

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>

Para abrir el puerto en iptables

[root@localhost ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
[root@localhost ~]# service iptables save