Instalando MySQL 5.6 no Linux CentOS 6.2

 Baixar arquivos RPM MySQL do site Oracle.

Vamos usar o MySQL 5.6.23 e Linux CentOS 64 bits neste exemplo de instalação.

[root@primary mysql_install]# pwd
/tmp/mysql_install
[root@primary mysql_install]# unzip V74390-01.zip
Archive:  V74390-01.zip
 extracting: MySQL-client-advanced-5.6.23-1.el6.x86_64.rpm
 extracting: MySQL-embedded-advanced-5.6.23-1.el6.x86_64.rpm
 extracting: MySQL-server-advanced-5.6.23-1.el6.x86_64.rpm
 extracting: MySQL-devel-advanced-5.6.23-1.el6.x86_64.rpm
 extracting: MySQL-test-advanced-5.6.23-1.el6.x86_64.rpm
 extracting: MySQL-shared-compat-advanced-5.6.23-1.el6.x86_64.rpm
 extracting: MySQL-shared-advanced-5.6.23-1.el6.x86_64.rpm
 extracting: README.txt
[root@primary mysql_install]# ll
total 454836
-rw-r--r-- 1 root root  18658700 Jan 30 08:08 MySQL-client-advanced-5.6.23-1.el6.x86_64.rpm
-rw-r--r-- 1 root root   3331064 Jan 30 08:08 MySQL-devel-advanced-5.6.23-1.el6.x86_64.rpm
-rw-r--r-- 1 root root  88718056 Jan 30 08:08 MySQL-embedded-advanced-5.6.23-1.el6.x86_64.rpm
-rw-r--r-- 1 root root  65170264 Jan 30 08:08 MySQL-server-advanced-5.6.23-1.el6.x86_64.rpm
-rw-r--r-- 1 root root   2031628 Jan 30 08:08 MySQL-shared-advanced-5.6.23-1.el6.x86_64.rpm
-rw-r--r-- 1 root root   3945168 Jan 30 08:08 MySQL-shared-compat-advanced-5.6.23-1.el6.x86_64.rpm
-rw-r--r-- 1 root root  50999164 Jan 30 08:09 MySQL-test-advanced-5.6.23-1.el6.x86_64.rpm
-rw-r--r-- 1 root root     11273 Feb  1 19:19 README.txt
-rw-r--r-- 1 root root 232866609 Mar  2 16:21 V74390-01.zip
[root@primary mysql_install]# rpm -ihv MySQL-*rpm
Preparing...                ########################################### [100%]
   1:MySQL-devel-advanced   ########################################### [ 14%]
   2:MySQL-client-advanced  ########################################### [ 29%]
   3:MySQL-test-advanced    ########################################### [ 43%]
   4:MySQL-embedded-advanced########################################### [ 57%]
   5:MySQL-shared-compat-adv########################################### [ 71%]
   6:MySQL-shared-advanced  ########################################### [ 86%]
   7:MySQL-server-advanced  ########################################### [100%]

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.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

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

WARNING: Found existing config file /usr/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/my-new.cnf,
please compare it with your file and take the changes you need.
  • Durante o tempo em que o instalador executa uma senha será gerada e armazenado dentro do arquivo .mysql_secret localizado no diretório /root.
[root@primary ~]# cat .mysql_secret
# The random password set for the root user at Mon Mar 2 18:05:41 2015 (local time): yRzDLGZGwrjDI0vv
  • Também um arquivo my.cnf será criado para você pelo instalador e sera localizado na /usr/my.cnf.
-o arquivo my.cnf é responsável pelas variáveis de configuração de banco de dados MySQL. Aqui está o conteúdo do arquivo de exemplo my.cnf, você pode alterar como você deseja. Também há um link dentro do arquivo que aponta a página do site MySQL que dá mais detalhes sobre os parâmetros de configuração.
[root@primary ~]# cat /usr/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  • Agora que temos a nossa senha de root e sabemos onde nosso arquivo my.cnf está localizado vamos iniciar o nosso serviço MySQL e logar em nosso banco de dados MySQL
Start MySQL 
[root@primary ~]# /etc/init.d/mysql start
Starting MySQL. SUCCESS!
Faça o login no banco de dados MySQL usando a senha dentro do .mysql_secret
[root@primary ~]# mysql -uroot -pyRzDLGZGwrjDI0vv
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.6.23-enterprise-commercial-advanced

Copyright (c) 2000, 2015, 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
Em seguida é preciso alterar a senha de root para atender as nossas necessidades. -Para este exemplo vou usar a senha 'root'.
mysql SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
Query OK, 0 rows affected (0.00 sec)

mysql flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql exit
Testa a senha
[root@primary ~]# mysql -uroot -proot
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.23-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2015, 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

Nosso banco de dados MySQL está instalado e funcionando. Esta foi uma instalação de banco de dados MySQL básica usando variáveis padrão para a instalação, vamos olhar em instalações MySQL personalizadas em artigos futuros.