Data

17 abr, 2014

Instalando o novo MySQL 5.7 via repositório YUM

Publicidade

Somente para contextualizar e citar alguns artigos que já escrevi, durante a MySQL User Conference de 2014, muito se ouviu falar sobre a nova versão 5.6 do MySQL, que já está em GA (General Available): os benefícios relacionados a performance e adoção de novos recursos como suporte a índices Full Text, antes somente suportados pelo Storage Engine MyISAM, a consolidação de uso do InnoDB com tablespaces individuais por tabela, habilitado pela opção innodb_file_per_table e pelo novo formato de arquivo BARRACUDA (vale dizer que esse recurso está presente no MySQL desde a versão 5.0 e, atualmente, na versão 5.6 está habilitada por padrão). A replicação no MySQL 5.6 passou por várias melhorias e a mais expressiva de todas realmente é a possibilidade de se configurar de 1 a 1024 threads no servidor SLAVE para que este tenha mais recursos para ler os dados vindos do servidor MASTER com mais rapidez, o que é chamado de multi-threaded slave.

Quanto à grande novidade que é o MySQL 5.7, muito está por vir, várias novidades já estão disponíveis no código dos binários que podem ser baixados do labs.mysql.com e podem ser testadas no seu laptop/máquina virtual. E é justamente isso que quero abordar aqui neste artigo, pois, há muito tempo, e a pedido da comunidade, finalmente a Oracle colocou à disposição um repositório através do qual podemos instalar versões mais novas do MySQL, mesmo aquelas que ainda estão em desenvolvimento. É possível, com poucos comandos, instalar o MySQL via YUM!

Recentemente, eu fiz um teste subindo uma máquina virtual com o MySQL 5.7 DMR 4. Antes de tudo, você baixa o arquivo de repositório do site do MySQL (você não precisa ir lá, pois já vou colocar logo abaixo a URL de requisição do arquivo via wget). Após baixar e instalar o arquivo de repositório, basta habilitar a versão do MySQL que você deseja instalar no servidor via yum-config-manager e, na sequência, instalar o mysql-server.

Passo 1 – instalar o repositório

[root@mysql57dmr4 ~]# rpm -Uvi https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Retrieving https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Preparing packages for installation…

Passo 2 – desabilitar a verificação para o MySQL 5.6

[root@mysql57dmr4 ~]# sudo yum-config-manager --disable mysql56-community
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit
=========== repo: mysql56-community ===========
[mysql56-community]
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/6
baseurl = http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/6/mysql56-community
cost = 1000
enabled = 0
enablegroups = True
exclude =
failovermethod = priority
gpgcadir = /var/lib/yum/repos/x86_64/6/mysql56-community/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/6/mysql56-community/gpgdir
gpgkey = file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/6/mysql56-community/headers
http_caching = all
includepkgs =
keepalive = True
mdpolicy = group:primary
mediaid =
metadata_expire = 21600
metalink =
mirrorlist =
mirrorlist_expire = 86400
name = MySQL 5.6 Community Server
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/6/mysql56-community
pkgdir = /var/cache/yum/x86_64/6/mysql56-community/packages
proxy =
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
username =

Passo 3 – Habilitando o repositório para a versão 5.7

[root@mysql57dmr4 ~]# sudo yum-config-manager --enable mysql57-community-dmr
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit
========== repo: mysql57-community-dmr =============
[mysql57-community-dmr]
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/6
baseurl = http://repo.mysql.com/yum/mysql-5.7-community/el/6/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/6/mysql57-community-dmr
cost = 1000
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
gpgcadir = /var/lib/yum/repos/x86_64/6/mysql57-community-dmr/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/6/mysql57-community-dmr/gpgdir
gpgkey = file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/6/mysql57-community-dmr/headers
http_caching = all
includepkgs =
keepalive = True
mdpolicy = group:primary
mediaid =
metadata_expire = 21600
metalink =
mirrorlist =
mirrorlist_expire = 86400
name = MySQL 5.7 Community Server Development Milestone Release
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/6/mysql57-community-dmr
pkgdir = /var/cache/yum/x86_64/6/mysql57-community-dmr/packages
proxy =
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
username =
Neste ponto, podemos verificar se já conseguirmos ver os pacotes do 5.7.4 disponíveis no repositório:
[root@mysql57dmr4 ~]# yum repolist enabled | grep "mysql.*-community.*"
Failed to set locale, defaulting to C
mysql-connectors-community MySQL Connectors Community                         6
mysql-tools-community      MySQL Tools Community                              6
mysql57-community-dmr      MySQL 5.7 Community Server Development Milesto    31
Caso o resultado seja parecido com aquele que foi exibido anteriormente, basta finalizar com a instalação do MySQL.

Passo 4 – instalando o MySQL 5.7 DMR 4

[root@mysql57dmr4 ~]# yum install mysql-server
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.globo.com
 * epel: mirror.globo.com
 * extras: mirror.globo.com
 * updates: mirror.globo.com
Setting up Install Process
Package mysql-server is obsoleted by mysql-community-server, trying to install mysql-community-server-5.7.4-0.3.m14.el6.x86_64 instead
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.4-0.3.m14.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.4-0.3.m14.el6 for package: mysql-community-server-5.7.4-0.3.m14.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) = 5.7.4-0.3.m14.el6 for package: mysql-community-server-5.7.4-0.3.m14.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.4-0.3.m14.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) = 5.7.4-0.3.m14.el6 for package: mysql-community-client-5.7.4-0.3.m14.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.7.4-0.3.m14.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.4-0.3.m14.el6 will be obsoleting
---> Package mysql-libs.x86_64 0:5.1.69-1.el6_4 will be obsoleted
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-2.2.el6_1.x86_64
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: perl-DBD-MySQL-4.013-3.el6.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-2.2.el6_1.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: perl-DBD-MySQL-4.013-3.el6.x86_64
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.4-0.3.m14.el6 will be obsoleting
---> Package postfix.x86_64 2:2.6.6-2.2.el6_1 will be updated
---> Package postfix.x86_64 2:2.6.6-6.el6_5 will be an update
--> Processing Dependency: libssl.so.10(libssl.so.10)(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Processing Dependency: libcrypto.so.10(libcrypto.so.10)(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.1)(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Running transaction check
---> Package openssl.x86_64 0:1.0.0-27.el6_4.2 will be updated
---> Package openssl.x86_64 0:1.0.1e-16.el6_5.7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================
 Package                               Arch             Version                     Repository                       Size
==========================================================================================================================
Installing:
 mysql-community-libs                  x86_64           5.7.4-0.3.m14.el6           mysql57-community-dmr           2.1 M
     replacing  mysql-libs.x86_64 5.1.69-1.el6_4
 mysql-community-libs-compat           x86_64           5.7.4-0.3.m14.el6           mysql57-community-dmr           1.6 M
     replacing  mysql-libs.x86_64 5.1.69-1.el6_4
 mysql-community-server                x86_64           5.7.4-0.3.m14.el6           mysql57-community-dmr            65 M
Installing for dependencies:
 mysql-community-client                x86_64           5.7.4-0.3.m14.el6           mysql57-community-dmr            20 M
 mysql-community-common                x86_64           5.7.4-0.3.m14.el6           mysql57-community-dmr           299 k
Updating for dependencies:
 openssl                               x86_64           1.0.1e-16.el6_5.7           updates                         1.5 M
 postfix                               x86_64           2:2.6.6-6.el6_5             updates                         2.0 M

Transaction Summary
==========================================================================================================================
Install       5 Package(s)
Upgrade       2 Package(s)

Total download size: 93 M
Is this ok [y/N]: y

Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql-community-common-5.7.4-0.3.m14.el6.x86_64                                                       1/10
  Installing : mysql-community-libs-5.7.4-0.3.m14.el6.x86_64                                                         2/10
  Updating   : openssl-1.0.1e-16.el6_5.7.x86_64                                                                      3/10
  Installing : mysql-community-libs-compat-5.7.4-0.3.m14.el6.x86_64                                                  4/10
  Installing : mysql-community-client-5.7.4-0.3.m14.el6.x86_64                                                       5/10
  Installing : mysql-community-server-5.7.4-0.3.m14.el6.x86_64                                                       6/10
  Updating   : 2:postfix-2.6.6-6.el6_5.x86_64                                                                        7/10
  Cleanup    : 2:postfix-2.6.6-2.2.el6_1.x86_64                                                                      8/10
  Erasing    : mysql-libs-5.1.69-1.el6_4.x86_64                                                                      9/10
  Cleanup    : openssl-1.0.0-27.el6_4.2.x86_64                                                                      10/10
  Verifying  : mysql-community-server-5.7.4-0.3.m14.el6.x86_64                                                       1/10
  Verifying  : openssl-1.0.1e-16.el6_5.7.x86_64                                                                      2/10
  Verifying  : mysql-community-client-5.7.4-0.3.m14.el6.x86_64                                                       3/10
  Verifying  : mysql-community-libs-5.7.4-0.3.m14.el6.x86_64                                                         4/10
  Verifying  : 2:postfix-2.6.6-6.el6_5.x86_64                                                                        5/10
  Verifying  : mysql-community-libs-compat-5.7.4-0.3.m14.el6.x86_64                                                  6/10
  Verifying  : mysql-community-common-5.7.4-0.3.m14.el6.x86_64                                                       7/10
  Verifying  : 2:postfix-2.6.6-2.2.el6_1.x86_64                                                                      8/10
  Verifying  : mysql-libs-5.1.69-1.el6_4.x86_64                                                                      9/10
  Verifying  : openssl-1.0.0-27.el6_4.2.x86_64                                                                      10/10

Installed:
  mysql-community-libs.x86_64 0:5.7.4-0.3.m14.el6           mysql-community-libs-compat.x86_64 0:5.7.4-0.3.m14.el6
  mysql-community-server.x86_64 0:5.7.4-0.3.m14.el6

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.4-0.3.m14.el6           mysql-community-common.x86_64 0:5.7.4-0.3.m14.el6

Dependency Updated:
  openssl.x86_64 0:1.0.1e-16.el6_5.7                            postfix.x86_64 2:2.6.6-6.el6_5

Replaced:
  mysql-libs.x86_64 0:5.1.69-1.el6_4

Complete!

Com isso, basta partir para a fase final da instalação do MySQL, que é iniciar o daemon via mysql.server ou mesmo, como mostro abaixo, com o comando service.

[root@mysql57dmr4 ~]# service mysqld start
Initializing MySQL database:

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

Securing the MySQL server deployment.

Connecting to MySQL server using password in '/root/.mysql_secret'

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:  2
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!

Como já acontece desde o MySQL 5.6, ao iniciar o MySQL 5.6++ pela primeira vez, a senha do usuário root do MySQL é criada em um arquivo oculto chamado “.mysql_secret”, que é localizado no diretório /root.

[root@mysql57dmr4 ~]# ls -lha | grep .mysql_se
-rw-------   1 root root  105 Apr 14 21:59 .mysql_secret

Pegamos o conteúdo desse arquivo e rodamos o mysql_secure_instalation, que agora é um programa escrito em C++, não mais um shell. Isso nos ajudará com a segurança do banco de dados, dando a oportunidade de excluir usuários anônimos, o banco de dados test, caso seja interessante alterar a senha atual para uma mais próxima daquilo que você utiliza normalmente. Neste ponto, saliento que, a validação de senhas já está habilitada por padrão no MySQL 5.7, então, se você quiser utilizar uma senha fraca, será necessário editar o arquivo de configuração do MySQL, comentando a opção que carrega o plugin validate_password.so. Mas como esse não é o caso, vamos rodar o mysql_secure_installation:

[root@mysql57dmr4 ~]# cat .mysql_secret
# The random password set for the root user at Mon Apr 14 21:59:46 2014 (local time):
CV]g6ynLzkRLgqb.

[root@mysql57dmr4 ~]# mysql_secure_installation -u root -p
Enter password:

Securing the MySQL server deployment.

The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing root password.

Estimated strength of the password: 100
Change the root password? (Press y|Y for Yes, any other key for No) : Yes

New password:P@ssw0rd
Re-enter new password: P@ssw0rd

Estimated strength of the password: 100
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) : N

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

O password P@ssw0rd que foi utilizado não aparecerá na sua linha de comando, eu adicionei somente para contextualizar. Sendo assim, nosso MySQL 5.7 DMR 4 já está pronto para rodar e seguro! No próximo artigo, vamos separar dados e logs em discos diferentes para iniciar um trabalho para melhorar a performance do banco. Até lá!!

[root@mysql57dmr4 ~]# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.4-m14 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> SELECT "HAPPY MYSQL'ING!!!!" AS MSG, "@imasters , @wagnerbianchijr" AS TWITTER;
+---------------------+------------------------------+
| MSG                 | TWITTER                      |
+---------------------+------------------------------+
| HAPPY MYSQL'ING!!!! | @imasters , @wagnerbianchijr |
+---------------------+------------------------------+
1 row in set (0.00 sec)

mysql> \q
Bye