Escolar Documentos
Profissional Documentos
Cultura Documentos
Administração
Backup & Recovery
Tuning
Alta Disponibilidade
2 2
Comandos no Treinamento
Comando com o usuário root:
# mysql -u root -pNerv2020.
Comando no MySQL:
mysql> SHOW DATABASES;
4 4
Por que MySQL?
https://db-engines.com/en/ranking
5 5
DBA MySQL
DBA MySQL e ...
●
Desenvolvedor
●
Administrador de Dados
●
Administrador de Sistema Operacional
●
DevOPS
●
Analista de Sistema
●
DBA de outro banco
6 6
Certificações
https://education.oracle.com/database/mysql/pFamily_406 7 7
Livros
●
MySQL 5.0 Certification Study Guide
●
High Performance MySQL
8 8
MySQL Blogs
9 9
MySQL Blogs
10 10
MySQL Blogs
11 11
MySQL Blogs
12 12
Fóruns
13 13
Documentação
https://dev.mysql.com/doc/refman/5.5/en/index.html
https://dev.mysql.com/doc/refman/5.6/en/index.html
https://dev.mysql.com/doc/refman/5.7/en/index.html
https://dev.mysql.com/doc/refman/8.0/en/
14 14
MySQL Internals Manual
15 15
Produtos MySQL
16 16
História do MySQL
17
História do MySQL
18
Open Source
19 19
Open Source
20 20
Open Source
21 21
Produtos Community
22 22
Produtos Enterprise
https://www.mysql.com/products/
23 23
Produtos Enterprise
https://www.mysql.com/products/
24 24
mysqlbackup
https://www.mysql.com/products/enterprise/backup.html
25 25
Thread Pool
https://www.mysql.com/products/enterprise/scalability.html 26 26
MySQL Enterprise Monitor
https://www.mysql.com/products/enterprise/monitor.html 27 27
MySQL Enterprise Monitor - MySQL Query Analyzer
https://www.mysql.com/products/enterprise/monitor.html 28 28
MySQL Enterprise Monitor - Database File IO
https://www.mysql.com/products/enterprise/monitor.html 29 29
MySQL Enterprise Monitor - MySQL Replication Topology View
https://www.mysql.com/products/enterprise/monitor.html 30 30
MySQL Enterprise Monitor - MySQL Cluster Topology View
https://www.mysql.com/products/enterprise/monitor.html 31 31
MySQL Enterprise Monitor - MySQL Replication Multi-Source
https://www.mysql.com/products/enterprise/monitor.html 32 32
MySQL Enterprise Monitor - MySQL Replication Status
https://www.mysql.com/products/enterprise/monitor.html 33 33
MySQL Enterprise Monitor - MySQL Enterprise Backup Dashboard
https://www.mysql.com/products/enterprise/monitor.html 34 34
Instalação
35 35
Instalação – Repositório Padrão
[root@CentOS-6 ~]# cat /etc/redhat-release
CentOS release 6.10 (Final)
[root@CentOS-6 ~]# yum -y install mysql-server
...
[root@CentOS-6 ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64
[root@CentOS-6 ~]#
36 36
Red Hat / CentOS / OEL e MySQL / MariaDB
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/
7.0_release_notes/chap-red_hat_enterprise_linux-7.0_release_notes-
web_servers_and_services
37 37
Instalação – Versão Específica
38 38
Instalação – Repositórios MySQL
https://dev.mysql.com/downloads/ 39 39
Lab 1.1: Instalação MySQL
Instale e habilite o reposítório do MySQL 5.7.
# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
# yum -y install mysql80-community-release-el7-3.noarch.rpm
# vi /etc/yum.repos.d/mysql-community.repo
...
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
...
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
...
41 41
Lab 1.3: Status MySQL
Verifique as formas de conexão com o MySQL.
# mysql -u root -p
mysql> STATUS;
mysql> EXIT;
# tail /var/log/mysqld.log
42 42
Lab 1.4: Client MySQL
Verifique as formas de conexão com o MySQL.
# mysql -u root -p
mysql> SHOW DATABASES;
mysql> EXIT;
# mysql -p
mysql> SHOW DATABASES;
mysql> EXIT;
# vi .my.cnf
[client]
password=Nerv2020.
prompt='\U-\d-\R:\m:\\s>'
# mysql 43 43
Lab 1.5: Client MySQL
Verifique as formas de execução de comandos no MySQL.
# mysql
mysql> SHOW DATABASES;
# mysql -e “SHOW DATABASES”
# mysql -e 'SHOW DATABASES'
# mysql -t -e 'SHOW DATABASES'
# mysql -B -e 'SHOW DATABASES'
# mysql -E -e 'SHOW DATABASES'
# mysql -X -e 'SHOW DATABASES'
mysql> \W
mysql> \w
# export EDITOR=vi
# mysql
mysql> SHOW DATABASES;
mysql> edit
mysql> ;
mysql> help
45 45
Engines
https://en.wikipedia.org/wiki/Comparison_of_MySQL_database_engines 46 46
Engines
Verifique as formas de execução de comandos no MySQL.
mysql> CREATE DATABASE test;
mysql> USE test;
47 47
Engines MySQL x Percona x MariaDB
48 48
Releases MySQL x Percona x MariaDB
https://www.percona.com/blog/2017/11/02/mysql-vs-mariadb-reality-check/ 49 49
MySQL x Percona Server
https://db-engines.com/en/ranking
50 50
Percona Server
51 51
Percona Server
52 52
Percona Server
53 53
Percona Server
https://www.percona.com/software/mysql-database/percona-server/benchmarks54 54
Percona Server
55 55
Percona Server
https://www.percona.com/software/mysql-database/percona-server/feature-comparison
56 56
Percona Server
https://www.percona.com/software/mysql-database/percona-server/feature-comparison
57 57
Percona Server
https://www.percona.com/software/mysql-database/percona-server/feature-comparison
58 58
Percona Server
https://www.percona.com/software/mysql-database/percona-server/feature-comparison
59 59
Lab 2.1: Percona Server
Instale o Oracle VM VirtualBox.
# yum -y install SDL kernel-uek-devel
# wget https://download.virtualbox.org/virtualbox/6.1.14/VirtualBox-6.1-
6.1.14_140239_el7-1.x86_64.rpm
# yum -y install VirtualBox-6.1-6.1.14_140239_el7-1.x86_64.rpm
60 60
Lab 2.2: Percona Server
No Oracle VM VirtualBox, clique em “File”, e em “Import Appliance”, e importe o arquivo
/root/Linux.ova.
61 61
Lab 2.3: Percona Server
62 62
Lab 2.4: Percona Server
63 63
Lab 2.5: Percona Server
64 64
Lab 2.6: Percona Server
Verifique o IP da VM, e a acesse via ssh.
# ip addr
65 65
MariaDB
https://en.wikipedia.org/wiki/MariaDB 66 66
MariaDB
https://mariadb.com/kb/en/library/mariadb-vs-mysql-features/ 67 67
MariaDB
https://mariadb.com/kb/en/library/mariadb-vs-mysql-features/ 68 68
MariaDB
https://mariadb.com/kb/en/library/mariadb-vs-mysql-features/ 69 69
MariaDB
https://mariadb.com/kb/en/library/optimizer-feature-comparison-matrix/
70 70
MariaDB
https://mariadb.com/kb/en/library/optimizer-feature-comparison-matrix/
71 71
MariaDB
https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/
72 72
MariaDB
https://mariadb.org/performance-evaluation-of-mariadb-10-1-and-mysql-5-7-4-labs-tplc/
73 73
MariaDB
74 74
MariaDB - Services
https://mariadb.com/services/
75 75
MariaDB - Subscription
https://mariadb.com/pricing/ 76 76
MariaDB - Subscription
https://mariadb.com/pricing/ 77 77
MariaDB x mariadb.org x mariadb.com
https://mariadb.org/about/
https://mariadb.org/about/#sponsors
https://mariadb.org/about/#board 78 78
MariaDB x mariadb.org x mariadb.com
https://mariadb.com/trademarks/ 79 79
Business Source License (BSL)
https://mariadb.com/bsl-faq-mariadb/ 80 80
Business Source License (BSL)
https://mariadb.com/projects-using-bsl-11/ 81 81
MariaDB - Parceiros
https://mariadb.com/kb/en/library/sql-diagnostic-manager-sqlyog/ 82 82
Lab 3.1: MariaDB
No Oracle VM VirtualBox, crie uma nova VM, com o nome “MariaDB”, importanto novamente o
arquivo /root/Linux.ova.
83 83
Lab 3.2: MariaDB
https://downloads.mariadb.org/mariadb/repositories 84 84
Lab 3.3: MariaDB
Verifique o IP da VM, e a acesse via ssh.
# ip addr
Instale o MariaDB.
# vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
86 86
Lab 4.1: Estruturas Físicas e Lógicas
Crie um novo banco de dados.
# mysql
mysql> SHOW TABLES;
mysql> SHOW DATABASES;
# mysql employees
mysql> SHOW TABLES;
87 87
Lab 4.2: Estruturas Físicas e Lógicas
Verifique as estruturas físicas dos MySQL.
# ls -lh /var/lib/mysql/
...
drwxr-x---. 2 mysql mysql 4.0K Nov 30 10:22 employees
-rw-r-----. 1 mysql mysql 13K Dec 1 19:21 ib_buffer_pool
-rw-r-----. 1 mysql mysql 48M Dec 1 19:21 ib_logfile0
-rw-r-----. 1 mysql mysql 48M Dec 1 19:21 ib_logfile1
drwxr-x---. 2 mysql mysql 84 Nov 30 10:22 menagerie
drwxr-x---. 2 mysql mysql 4.0K Nov 30 10:22 mysql
drwxr-x---. 2 mysql mysql 20 Dec 1 18:56 nerv
drwxr-x---. 2 mysql mysql 8.0K Nov 30 08:47 performance_schema
drwxr-x---. 2 mysql mysql 4.0K Nov 30 10:22 sakila
drwxr-x---. 2 mysql mysql 8.0K Nov 30 08:47 sys
drwxr-x---. 2 mysql mysql 4.0K Nov 30 10:37 test
drwxr-x---. 2 mysql mysql 4.0K Nov 30 10:22 world
...
[root@MySQL-01 ~]#
# ls -lh /var/lib/mysql/nerv/
-rw-rw----. 1 mysql mysql 65 Out 26 15:57 db.opt
# cat /var/lib/mysql/nerv/db.opt
default-character-set=latin1
default-collation=latin1_swedish_ci
# ls -lh /var/lib/mysql/menagerie/
# ls -lh /var/lib/mysql/mysql/
88 88
Lab 4.3: Dicionário de Dados
Verifique o conteúdo das tabelas do banco mysql.
# mysql
mysql> USE mysql;
mysql> SHOW TABLES;
mysql> SELECT * FROM db;
mysql> SELECT * FROM user;
89 89
Lab 4.4: Dicionário de Dados
Verifique o conteúdo das tabelas do banco information_schema.
# mysql
mysql> USE information_schema;
mysql> SHOW TABLES;
mysql> SELECT * FROM TABLES;
mysql> SELECT * FROM USER_PRIVILEGES;
http://dev.mysql.com/doc/refman/5.7/en/information-schema.html
90 90
Lab 4.5: Dicionário de Dados
Verifique o conteúdo das tabelas do banco performance_schema.
# mysql
mysql> USE performance_schema;
mysql> SHOW TABLES;
mysql> SELECT * FROM threads;
mysql> SELECT * FROM users;
http://dev.mysql.com/doc/refman/5.7/en/performance-schema.html
http://dev.mysql.com/doc/refman/5.7/en/performance-schema-table-index.html
http://dev.mysql.com/doc/refman/5.7/en/sys-schema.html 91 91
Lab 4.6: Variables, Status, Thread States
Verifique as Variables, Status, e Thread States.
# mysql
mysql> SHOW VARIABLES;
mysql> SHOW VARIABLES LIKE '%wait%';
Variables
http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html
https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html
Status Variables
http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html
Thread States
http://dev.mysql.com/doc/refman/5.7/en/general-thread-states.html 92 92
Variables
93 93
Variables
94 94
Lab 4.7: Variables
Altere uma Variable, com SET e com SET GLOBAL.
# mysql
mysql> SHOW VARIABLES LIKE '%sort%';
mysql> SET sort_buffer_size=524288; (OU SET @@local.sort_buffer_size=524288;)
mysql> SHOW VARIABLES LIKE '%sort%'; (OU SELECT @@local.sort_buffer_size;)
mysql> SELECT @@global.sort_buffer_size;
mysql> EXIT;
# mysql
mysql> SHOW VARIABLES LIKE '%sort%';
mysql> SELECT @@local.sort_buffer_size;
# mysql
mysql> SHOW VARIABLES LIKE '%sort%';
mysql> SET GLOBAL sort_buffer_size=524288; (OU SET @@global.sort_buffer_size=524288;)
mysql> SHOW VARIABLES LIKE '%sort%'; (OU SELECT @@local.sort_buffer_size;)
mysql> SELECT @@global.sort_buffer_size;
mysql> EXIT;
# mysql
mysql> SHOW VARIABLES LIKE '%sort%';
95 95
Lab 4.8: Variables
Altere uma Variable pelo arquivo de parâmetros.
# mysql
mysql> SHOW VARIABLES LIKE '%sort%';
mysql> exit;
# vi /etc/my.cnf
...
[mysqld]
sort_buffer_size = 2M
...
# mysql
mysql> SHOW VARIABLES LIKE '%sort%';
96 96
Lab 4.9: Usuários e Permissões
Crie um usuário para conexão remota.
mysql> CREATE USER 'ricardo'@'localhost' IDENTIFIED BY 'Nerv2020.';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ricardo'@'localhost';
mysql> REVOKE ALL PRIVILEGES ON *.* FROM 'ricardo'@'localhost';
mysql> DROP USER 'ricardo'@'localhost';
98 98
Lab 4.10: Importação e Exportação
Exporte as tabelas do banco employees para texto.
mysql> USE employees;
mysql> SELECT * FROM departments INTO OUTFILE '/tmp/departments.txt';
O que aconteceu?
Outras opções:
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'; 99 99
Lab 4.11: Importação e Exportação
Importe os arquivos texto para as tabelas do banco employees.
mysql> CREATE DATABASE employees_dev;
mysql> USE employees_dev;
mysql> CREATE TABLE departments AS SELECT * FROM employees.departments WHERE 1=0;
mysql> CREATE TABLE dept_emp AS SELECT * FROM employees.dept_emp WHERE 1=0;
mysql> CREATE TABLE dept_manager AS SELECT * FROM employees.dept_manager WHERE 1=0;
mysql> CREATE TABLE employees AS SELECT * FROM employees.employees WHERE 1=0;
mysql> CREATE TABLE salaries AS SELECT * FROM employees.salaries WHERE 1=0;
mysql> CREATE TABLE titles AS SELECT * FROM employees.titles WHERE 1=0;
100 100
Lab 4.12: Velocidade de Importação e Exportação
Teste a velocidade de exportação e importação com uma tabela maior.
mysql> USE nerv;
mysql> CREATE TABLE salaries_BIG AS SELECT * FROM employees.salaries;
mysql> INSERT INTO salaries_BIG SELECT * FROM salaries_BIG;
mysql> INSERT INTO salaries_BIG SELECT * FROM salaries_BIG;
mysql> INSERT INTO salaries_BIG SELECT * FROM salaries_BIG;
mysql> SELECT COUNT(*) FROM salaries_BIG;
mysql> SELECT * FROM salaries_BIG INTO OUTFILE '/var/lib/mysql-files/BIG.txt';
mysql> TRUNCATE TABLE salaries_BIG;
mysql> LOAD DATA INFILE '/var/lib/mysql-files/BIG.txt' INTO TABLE salaries_BIG;
101 101
Lab 4.13: MySQL Workbench
Instale o MySQL Workbench.
# yum -y install mysql-workbench-community
# mysql-workbench
102 102
Lab 4.14: MySQL Workbench
103 103
Lab 4.15: MySQL Workbench
104 104
Lab 4.16: MySQL Workbench
105 105
Lab 4.17: MySQL Workbench
106 106
Lab 4.18: MySQL Workbench
107 107
Lab 4.19: MySQL Workbench
108 108
Lab 4.20: MySQL Workbench
109 109
Lab 4.21: MySQL Workbench
110 110
Lab 4.22: MySQL Workbench
111 111
Lab 4.23: MySQL Workbench
112 112
Lab 4.24: MySQL Workbench
113 113
Lab 4.25: MySQL Workbench
114 114
Lab 4.26: MySQL Workbench
115 115
Lab 4.27: MySQL Workbench
116 116
Lab 4.28: MySQL Workbench
117 117
Lab 4.29: MySQL Workbench
118 118
Lab 4.30: MySQL Workbench
119 119
Lab 4.31: MySQL Workbench
120 120
Lab 4.32: MySQL Workbench
121 121
Lab 4.33: MySQL Workbench
122 122
Lab 4.34: MySQL Workbench
123 123
Lab 4.35: MySQL Workbench
124 124
Lab 4.36: MySQL Workbench
125 125
Lab 4.37: MySQL Variables: Conexões
Altere estas Variables pelo arquivo de parâmetros, e reinicie o MySQL.
max_connections = 1000 # default = 151
max_user_connections = 0
thread_cache_size = 200 # default = 8 + (max_connections / 100)
back_log = 100 # default = max_connections / 5
slow_launch_time = 2 # Slow_launch_threads
connect_timeout = 10
net_read_timeout = 30
net_write_timeout = 60
net_retry_count = 10 # FLUSH HOSTS
net_buffer_length = 16384
max_allowed_packet = 4194304
127 127
Lab 4.38: MySQL Variables: Logs
Altere estas Variables pelo arquivo de parâmetros, e reinicie o MySQL.
log_output = FILE
log_error_verbosity = 3
log_error = /var/lib/mysql/mysql-error.log
general_log = OFF
general_log_file = /var/lib/mysql/mysql-general.log
slow_query_log = ON
slow_query_log_file = /var/lib/mysql/mysql-slow.log
long_query_time = 10
min_examined_row_limit = 10
log_slow_admin_statements = ON
log_queries_not_using_indexes = ON
log_throttle_queries_not_using_indexes = 1000
128 128
Lab 4.39: Event Scheduler
Habilite o Event Scheduler
mysql> SELECT @@GLOBAL.event_scheduler;
mysql> SHOW PROCESSLIST;
mysql> SET GLOBAL event_scheduler = ON;
mysql> SELECT @@GLOBAL.event_scheduler;
mysql> SHOW PROCESSLIST;
mysql> SELECT @@GLOBAL.event_scheduler;
129 129
Lab 4.40: Event Scheduler
Habilite o Event Scheduler
mysql> SHOW EVENTS;
131 131
Engines
●
MyISAM
●
InnoDB
●
Memory (MyISAM-like)
●
Archive (MyISAM-like)
●
CSV
●
Merge (MyISAM-like)
●
Federated
●
NDB (MyISAM-like)
●
Blackhole
●
Example
●
Aria
●
Percona XtraDB (InnoDB-like)
●
Percona XtraDB Cluster (InnoDB-like)
●
Percona TokuDB
132 132
Lab 5.1: Backup & Recovery
No Oracle VM VirtualBox, crie uma nova VM, com o nome “Restore”, importanto novamente o
arquivo /root/Linux.ova.
Verifique o IP da VM, e a acesse via ssh.
# ip addr
133 133
Lab 5.2: Cold Backup
Execute um Cold Backup.
# systemctl stop mysqld
# mkdir /root/ColdBackup
# cp -rfvp /var/lib/mysql/ /root/ColdBackup/
# systemctl start mysqld
134 134
Lab 5.3: Not-so-cold Backup MyISAM
Duplique as tabelas do banco employees no banco nerv.
mysql> USE nerv;
mysql> CREATE TABLE departments AS SELECT * FROM employees.departments;
mysql> CREATE TABLE dept_emp AS SELECT * FROM employees.dept_emp;
mysql> CREATE TABLE dept_manager AS SELECT * FROM employees.dept_manager;
mysql> CREATE TABLE employees AS SELECT * FROM employees.employees;
mysql> CREATE TABLE salaries AS SELECT * FROM employees.salaries;
mysql> CREATE TABLE titles AS SELECT * FROM employees.titles;
135 135
Lab 5.4: Not-so-cold Backup MyISAM
Coloque as tabelas MyISAM em LOCK.
mysql> SHOW OPEN TABLES FROM nerv;
mysql> FLUSH TABLE departments, dept_emp, dept_manager, employees, salaries,titles
WITH READ LOCK;
mysql> SHOW OPEN TABLES FROM nerv;
–-single-transaction
--lock-all-tables
--events
--routines
--compress
--quick
--no-autocommit
138 138
Lab 5.7: mydumper / myloader
Copie os Dumps para a VM de Restore.
# wget https://github.com/maxbube/mydumper/releases/download/v0.9.5/mydumper-0.9.5-
2.el7.x86_64.rpm
# yum -y install mydumper-0.9.5-2.el7.x86_64.rpm
# top -H
# mydumper --trx-consistency-only --routines --triggers --events --compress -–
threads=8 --logfile /root/mydumper-all.out --verbose=3
# mydumper --trx-consistency-only --routines --triggers --events --compress --
threads=8 --logfile /root/mydumper-nerv.out –verbose=3 ––database=nerv
# ls -lh export*
139 139
Lab 5.8: Bin Logs
Adicione no /etc/my.cnf as linhas abaixo, e reinicie 3 vezes o mysql.
server_id = 1
sync_binlog = 1
log-bin = mysql-bin
expire_logs_days = 32
Que novos arquivos passaram a existir no diretório de dados?
141 141
XtraBackup
142 142
XtraBackup / MyQL Enterprise Backup / Mariabackup
Percona Percona XtraBackup 1.4
Released on November 22, 2010
https://www.percona.com/doc/percona-xtrabackup/2.4/release-notes/1.4.html
143 143
XtraBackup
Execute um backup.
# mkdir -p /root/XtraBackup/
# export HORADOBACKUP=`date +%Y%m%d-%H%M%S`
# xtrabackup --backup --parallel=4 --target-dir=/root/XtraBackup/XtraBackup-
$HORADOBACKUP/
# xtrabackup --prepare --target-dir=/root/XtraBackup/XtraBackup-$HORADOBACKUP/
# ls -lh /root/XtraBackup/XtraBackup-$HORADOBACKUP/
# cat /root/XtraBackup/XtraBackup-$HORADOBACKUP/xtrabackup_binlog_info
Restaure o backup.
# systemctl stop mysqld
# rm -rf /var/lib/mysql/*
# xtrabackup --copy-back --target-dir=/root/XtraBackup/XtraBackup-$HORADOBACKUP/
# chown -R mysql:mysql /var/lib/mysql
# systemctl start mysqld
147 147
Lab 5.11: xtrabackup
Na VM de Restore, pare o MySQL.
# systemctl stop mysqld
# rm -rf /var/lib/mysql/*
148 148
Lab 5.12: xtrabackup
Crie os diretórios para os backups incrementais.
# mkdir /root/XtraBackup/base
# mkdir /root/XtraBackup/incremental1
# mkdir /root/XtraBackup/incremental2
# mkdir /root/XtraBackup/incremental3
150 150
Lab 5.14: xtrabackup / innobackupex
152 152
Lab 5.16: xtrabackup / innobackupex
Atualize o backup base com os backups incrementais.
# innobackupex --decompress --parallel=4 /root/XtraBackup/compress/base/
# innobackupex --apply-log --redo-only --use-memory=1G /root/XtraBackup/compress/base/
# rm -rf /root/XtraBackup/compress/base/*.qp
153 153
Tuning
154 154
Lab 6.1: datadir
Altere a localização do diretório de dados do MySQL.
# systemctl stop mysqld
# mkdir /mysql
# cp -R -p -v /var/lib/mysql/* /mysql/
# vi /etc/my.cnf
...
datadir=/mysql
...
155 155
Lab 6.2: InnoDB System Tablespace
Altere a localização da System Tablespace do InnoDB do MySQL.
# systemctl stop mysqld
# mkdir /InnoDB01
# mv /mysql/ibdata1 /InnoDB01/
# vi /etc/my.cnf
...
innodb_file_per_table=OFF
innodb_data_home_dir=
innodb_data_file_path=/InnoDB01/ibdata1:10M:autoextend:max:10G
...
156 156
Lab 6.3: Bin Logs
Altere a localização dos Bin Logs do MySQL.
# systemctl stop mysqld
# mkdir /BinLogs
# mv /mysql/mysql-bin* /BinLogs/
# vi /etc/my.cnf
...
log-bin=/BinLogs/mysql-bin
...
157 157
Lab 6.4: InnoDB Logs
Altere a localização dos Logs do InnoDB.
# systemctl stop mysqld
# mkdir /InnoDBLogs
# mv /mysql/ib_logfile* /InnoDBLogs/
# vi /etc/my.cnf
...
innodb_log_group_home_dir=/InnoDBLogs/
...
158 158
Lab 6.5: Tablespaces InnoDB
Crie uma TABLESPACE, e mova tabelas para ela.
# mkdir /BigTablespace
159 159
Engines: InnoDB
160 160
Engines: MyISAM
161 161
Engines: Memory
162 162
Engines: Archive
163 163
Lab 6.6: myisampack
Crie uma tabela graande, e teste sua velocidade de leitura antes e depois da compactação.
mysql> CREATE TABLE nerv.salaries_BIG_RO AS SELECT * FROM nerv.salaries_BIG;
mysql> ALTER TABLE nerv.salaries_BIG_RO Engine=MyISAM;
mysql> INSERT INTO nerv.salaries_BIG_RO SELECT * FROM nerv.salaries_BIG_RO;
mysql> INSERT INTO nerv.salaries_BIG_RO SELECT * FROM nerv.salaries_BIG_RO;
mysql> INSERT INTO nerv.salaries_BIG_RO SELECT * FROM nerv.salaries_BIG_RO;
mysql> CREATE INDEX IX_salaries_BIG_RO_emp_no ON nerv.salaries_BIG_RO(emp_no);
165 165
Lab 6.8: Benchmark - sysbench
Instale o sysbench.
# yum -y install sysbench
166 166
Lab 6.9: Benchmark - sysbench
Durante a execução do teste, acompanhe no MySQL, via mysqladmin.
mysql> drop database sbtest;
mysql> create database sbtest;
mysql> grant all privileges on sbtest.* to 'sbtest'@'localhost';
167 167
Lab 6.10: mytop
Instale o mytop.
# yum -y install mytop
# mytop -d mysql
168 168
Lab 6.11: innotop
Instale o innotop.
# yum -y install innotop
# innotop
169 169
Lab 6.12: SHOW ENGINE INNODB
Execute novamente os teste de carga com InnoDB, e acompanhe pelo comando abaixo.
# mysql -E -e "SHOW ENGINE INNODB STATUS"
170 170
Engines: CSV
171 171
Engines: Merge
172 172
Engines: Federated
173 173
Engines: Federated - Connection
174 174
Engines: Federated - Server
175 175
Engines: Blackhole
176 176
Engines: Example
177 177
Lab 6.13: Parâmetros de Tuning
Altere os parâmetros abaixo de forma a otimizar os Labs 4.12, 5.6, 6.6, 6.7 e 6.9.
### Huge Pages
large_pages = OFF
https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html
https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html
178 178
Lab 6.14: Parâmetros de Tuning
Altere os parâmetros abaixo de forma a otimizar os Labs 4.12, 5.6, 6.6, 6.7 e 6.9.
### Metadata
open_files_limit = 10000
table_open_cache = 400 # (Opened_tables)
table_open_cache_instances = 1 # Thread State Opening tables
table_definition_cache = 600 # (400 + (table_open_cache / 2))
metadata_locks_cache_size = 1024 # (Waiting for table metadata lock)
metadata_locks_hash_instances = 8 # (Waiting for table metadata lock)
max_prepared_stmt_count = 16382 # (Com_prepare_sql Prepared_stmt_count)
query_prealloc_size = 8192
query_alloc_block_size = 8192
stored_program_cache = 256
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
179 179
Lab 6.15: Parâmetros de Tuning
Altere os parâmetros abaixo de forma a otimizar os Labs 4.12, 5.6, 6.6, 6.7 e 6.9.
### MyISAM
key_cache_block_size = 4096
key_buffer_size = 128M # 25% RAM
key_cache_age_threshold = 300
key_cache_division_limit = 100 # (Hot)
bulk_insert_buffer_size = 8388608
concurrent_insert = ALWAYS
delay_key_write = ALL
low_priority_updates = OFF # (INSERT, UPDATE, DELETE, LOCK TABLE WRITE)
myisam_sort_buffer_size = 8388608 # (REPAIR TABLE, CREATE INDEX, ALTER TABLE)
myisam_max_sort_file_size = 2147483648 # (REPAIR TABLE,ALTER TABLE, LOAD DATA INFILE)
Exemplo:
prod.key_buffer_size = 128M
dev.key_buffer_size = 16M
mysql> CACHE INDEX t1, t2, t3 IN prod;
180 180
Lab 6.16: Parâmetros de Tuning
Altere os parâmetros abaixo de forma a otimizar os Labs 4.12, 5.6, 6.6, 6.7 e 6.9.
### InnoDB Files
innodb_checksums = ON # < 5.7
innodb_checksum_algorithm = crc32
innodb_doublewrite = OFF
innodb_autoextend_increment = 64
innodb_file_per_table = 1
innodb_file_format = Barracuda
innodb_compression_level = 6
innodb_compression_failure_threshold_pct = 0
innodb_compression_pad_pct_max = 50
### Lock
innodb_lock_wait_timeout = 50
innodb_rollback_on_timeout = OFF
181 181
Lab 6.17: Parâmetros de Tuning
Altere os parâmetros abaixo de forma a otimizar os Labs 4.12, 5.6, 6.6, 6.7 e 6.9.
### InnoDB Buffer
innodb_page_size = 16384
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 1 # 1 para cada 10GB de innodb_buffer_pool_size
innodb_change_buffering = ALL
innodb_change_buffer_max_size = 25
innodb_buffer_pool_dump_at_shutdown = ON
innodb_buffer_pool_load_at_startup = ON
innodb_buffer_pool_dump_now = OFF
innodb_buffer_pool_load_now = OFF
innodb_buffer_pool_load_abort = OFF
innodb_buffer_pool_filename = InnoDB.dump
innodb_buffer_pool_dump_pct = 100
182 182
Lab 6.18: Parâmetros de Tuning
Altere os parâmetros abaixo de forma a otimizar os Labs 4.12, 5.6, 6.6, 6.7 e 6.9.
### InnoDB Flush
innodb_use_native_aio = ON # Linux
innodb_flush_method = O_DIRECT
innodb_flush_neighbors = 1 # (0 em SSD)
innodb_adaptive_flushing = ON
innodb_flushing_avg_loops = 30
innodb_adaptive_flushing_lwm = 10
innodb_lru_scan_depth = 1024
innodb_max_dirty_pages_pct_lwm = 10
innodb_max_dirty_pages_pct = 75
innodb_old_blocks_pct = 37
innodb_old_blocks_time = 1000
innodb_io_capacity = 200
innodb_io_capacity_max = 2000
183 183
Lab 6.19: Parâmetros de Tuning
Altere os parâmetros abaixo de forma a otimizar os Labs 4.12, 5.6, 6.6, 6.7 e 6.9.
### InnoDB Statistics
innodb_stats_auto_recalc = ON
innodb_stats_transient_sample_pages = 8 # (STATS_SAMPLE_PAGES)
innodb_stats_persistent = ON
innodb_stats_persistent_sample_pages = 20 # (STATS_SAMPLE_PAGES)
184 184
Parâmetros de Tuning - Optimizer
185 185
Lab 6.20: Parâmetros de Tuning
Altere os parâmetros abaixo de forma a otimizar os Labs 4.12, 5.6, 6.6, 6.7 e 6.9.
### Optimizer
optimizer_prune_level = 1
optimizer_search_depth = 62
eq_range_index_dive_limit = 10
max_seeks_for_key = 1000
optimizer_switch=index_merge=on,index_merge_union=on,index_merge_sort_union=o
n,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pu
shdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=of
f,materialization=on,semijoin=on,loosescan=on,firstmatch=on,subquery_material
ization_cost_based=on,use_index_extensions=on
186 186
Lab 6.21: Transações e Isolamento
Altere todos os parâmetros abaixo no arquivo de parâmetros, e reinicie o MySQL.
mysql> use nerv;
mysql> CREATE TABLE teste1 (c1 int, c2 char(50), c3 varchar(255))
Engine=InnoDB;
mysql> CREATE TABLE teste2 (c1 int, c2 char(50), c3 varchar(255))
Engine=MyISAM;
187 187
Lab 6.22: Transações e Isolamento
1a Sessão: 2a Sessão:
mysql> update teste1 set c2 = 'BBB';
mysql> select * from teste1; mysql> select * from teste1;
mysql> commit;
mysql> select * from teste1; mysql> select * from teste1;
mysql> commit;
mysql> select * from teste1; mysql> select * from teste1;
3a Sessão:
mysql> SHOW PROCESSLIST;
mysql> SELECT waiting_trx_id, waiting_pid, waiting_query, blocking_trx_id,
blocking_pid, blocking_query FROM sys.innodb_lock_waits;
mysql> KILL 22;
188 188
Lab 6.23: Transações e Isolamento
1a Sessão: 2a Sessão:
mysql> update teste2 set c2 = 'BBB';
mysql> select * from teste2; mysql> select * from teste2;
mysql> commit;
mysql> select * from teste2; mysql> select * from teste2;
mysql> commit;
mysql> select * from teste2; mysql> select * from teste2;
189 189
Lab 6.24: Comandos Administrativos
Execute estas operações no banco employees e nerv:
mysql> ANALYZE TABLE employees.salaries;
mysql> INSERT INTO nerv.salaries SELECT * FROM employees.salaries;
mysql> ANALYZE TABLE nerv.salaries;
# ls -lh /mysql/nerv/salaries.*
mysql> OPTIMIZE TABLE nerv.salaries;
# ls -lh /mysql/nerv/salaries.*
mysql> DELETE FROM nerv.salaries;
# ls -lh /mysql/nerv/salaries.*
mysql> OPTIMIZE TABLE nerv.salaries;
mysql> OPTIMIZE TABLE nerv.salaries;
# ls -lh /mysql/nerv/salaries.*
191 191
Lab 6.26: EXPLAIN
mysql> use sakila;
mysql> EXPLAIN SELECT actor.first_name, actor.last_name, film.title
FROM actor, film, film_actor
WHERE actor.first_name = 'ADAM' AND
actor.actor_id = film_actor.actor_id AND
film_actor.film_id AND
film.film_id = film_actor.film_id;
192 192
Lab 6.27: SHOW PROFILE
193 193
Partitioning
194 194
Partitioning - RANGE
195 195
Partitioning - RANGE
196 196
Partitioning - LIST
197 197
Partitioning - RANGE COLUMNS
198 198
Partitioning - LIST COLUMNS
199 199
Partitioning - HASH
200 200
Partitioning - KEY
201 201
memcached
203 203
Alta Disponibilidade
204 204
Alta Disponibilidade
DRBD / Pacemaker / Corosync
205 205
Alta Disponibilidade
Windows Server Failover Clustering
206 206
Alta Disponibilidade
MySQL Replication
207 207
Lab 7.1: MySQL Replication
No Oracle VM VirtualBox, crie uma nova VM, com o nome “Slave 01”, importanto novamente o
arquivo /root/Linux.ova.
Inicie a VM, verifique seu IP, e acesse por ssh.
Pelo nmtui, altere o hostname da VM.
209 209
MySQL Parallel Replication
Altere os parâmetros abaixo:
slave_parallel_type = LOGICAL_CLOCK
slave_parallel_workers = 20
210 210
MySQL Proxy
211 211
Alta Disponibilidade
ProxySQL
# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
# yum -y install mysql80-community-release-el7-3.noarch.rpm
# vi /etc/yum.repos.d/mysql-community.repo
214 214
Alta Disponibilidade
MySQL Cluster / NDB Cluster
215 215
Alta Disponibilidade
InnoDB Cluster / Group Replication / Router / Shell / Fabric
216 216
MySQL Group Replication
217 217
MySQL Labs
218 218
Alta Disponibilidade
Galera Cluster
219 219
Alta Disponibilidade
Galera Cluster
220 220
Alta Disponibilidade
Percona XtraDB Cluster
221 221
Upgrade para 8.0
222 222
Upgrade
Supported Upgrade Methods
In-place Upgrade (mysql_upgrade)
Logical Upgrade (mysqldump)
●
Para um (apenas um) Release Series superior.
Por exemplo, de 5.6.27 para 5.7.9 (antes faça upgrade da Release Series Version).
Exemplos:
5.6: Release Series
5.6.20: Release Series Version
223 223
Upgrade
Changes in MySQL 5.7 / Changes in MySQL 8.0
https://dev.mysql.com/doc/refman/5.7/en/upgrading-from-previous-series.html
https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html
Índice de alterações:
https://dev.mysql.com/doc/relnotes/mysql/5.6/en/ix01.html
https://dev.mysql.com/doc/relnotes/mysql/5.7/en/ix01.html
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/ix01.html
224 224
Upgrade
225 225
Upgrade
226 226
8.0 New Features
http://mysqlserverteam.com/the-mysql-8-0-0-milestone-release-is-available/
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/ 227 227
Lab 9.1: Upgrade para 8.0
Edite o arquivo /etc/yum.repos.d/mysql-community.repo, e habilite o reposítório do MySQL 8.0.
...
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=0
gpgcheck=1
...
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/
enabled=1
gpgcheck=1
...
230 230
Lab Extra 1.2: Banco de Exemplo SAKILA
# cd
# wget http://downloads.mysql.com/docs/sakila-db.zip
# ls -lh sakila-db.zip
# unzip sakila-db.zip
# ls -lh sakila-db/
# cd sakila-db/
# mysql < sakila-schema.sql
# mysql < sakila-data.sql
231 231
Lab Extra 1.3: Banco de Exemplo MENAGERIE
# cd
# wget http://downloads.mysql.com/docs/menagerie-db.zip
# ls -lh menagerie-db.zip
# unzip menagerie-db.zip
# ls -lh menagerie-db/
# cd menagerie-db/
# cat pet.txt
# cat event.txt
# mysql -t
mysql> CREATE DATABASE menagerie;
mysql> use menagerie;
mysql> SOURCE cr_pet_tbl.sql
mysql> LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;
mysql> SOURCE ins_puff_rec.sql
mysql> SOURCE cr_event_tbl.sql
mysql> LOAD DATA LOCAL INFILE 'event.txt' INTO TABLE event;
232 232
Lab Extra 1.4: Banco de Exemplo EMPLOYEES
# cd
# wget https://launchpad.net/test-db/employees-db-1/1.0.6/+download/employees_db-
full-1.0.6.tar.bz2
# ls -lh employees_db-full-1.0.6.tar.bz2
# bunzip2 employees_db-full-1.0.6.tar.bz2
# tar xfv employees_db-full-1.0.6.tar
# ls -lh employees_db/
# cd employees_db/
# vi employees.sql
...
-- set storage_engine = InnoDB;
...
-- select CONCAT('storage engine: ', @@storage_engine) as INFO;
...
233 233
Lab Extra 1.5: Banco de Exemplo
# mysql
mysql> use employees;
mysql> show tables;
# mysql employees
mysql> show tables;
# mysql
mysql> select count(*) from employees.salaries;
mysql> select count(*) from menagerie.pet;
234 234
Fim