SlideShare a Scribd company logo
HOW (NOT) TO KILL YOUR
MYSQL INFRASTRUCTURE
Based on true stories
2
• Miklos ‘Mukka’ Szel
• From Hungary
• Started using Linux in 1997 and MySQL in 2000, used to be a backend
developer
• Worked for Own Startup, ISP, Walt Disney(ESPN,Cricinfo),
PalominoDB/Pythian
• Freelance Consultant since 2015 - Edmodo
/ME
3
Ansible:
- name: Install MySQL-Oracle Server
yum: pkg={{ item }} state=present
with_items:
- MySQL-server
- MySQL-client
Centos/Redhat:
yum install MySQL-server
Debian/Ubuntu:
apt-get install percona-server-server-5.6
1. VERSION MISMATCH - SOFTWARE
4
./pt-slave-find --host 10.77.3.181 -u root--ask-pass
Enter password:
10.77.24.181
Version 5.6.32-78.1-log
Server ID 134
Uptime 318+06:01:55 (started 2015-11-19T02:42:03)
Replication Is not a slave, has 1 slaves connected, is not read_only
Filters
Binary logging MIXED
Slave status
Slave mode STRICT
InnoDB version 5.6.32-78.1
+- 10.77.25.17
Version 5.6.27-75.0-log
Server ID 143
Uptime 167+18:21:03 (started 2016 -04-17T14:22:55)
Replication Is a slave, has 0 slaves connected, is read_only
Filters
Binary logging MIXED
Slave status 0 seconds behind, running, no errors
Slave mode STRICT
Auto-increment increment 2, offset 1
InnoDB version 5.6.27-75.0
1. VERSION MISMATCH - SOFTWARE
5
• Monitoring
• Check the process list on every server
• Scan for port
 nmap -p 3306 –sV 10.77.3.0/24
 Nmap scan report for 10.77.3.238
 Host is up (0.00087s latency).
 PORT STATE SERVICE VERSION
 3306/tcp open mysql MySQL 5.6.27-75.0-log
1. VERSION MISMATCH - SOFTWARE
6
• Between config file and runtime variables
• Between servers in the same replication chain
./pt-config-diff /etc/my.cnf h=localhost
3 config differences
Variable /etc/my.cnf c1-adhoc4-i.us-west2
========================================
innodb_thread_concurrency 0 4
wait_timeout 600 3600
read_only ON OFF
https://www.percona.com/doc/percona-toolkit/2.2/pt-config-diff.html
2. VERSION MISMATCH - CONFIG
7
• Don’t use methods like removing dots from ip addresses
• 10.77.12.3 (1077123)
• 10.77.1.23 (1077123)
• MySQL truncates the server_id if it’s bigger than the max value for an INT(4294967295)
• 192.168.111.222 (192168111222 -> 4294967295)
• 192.168.222.222 (192168222222 -> 4294967295)
• 4508354421957495439 -> 4294967295
• 12354356476576 -> 4294967295
3. MY.CNF – SERVER_ID
8
• Wait_timeout 28800 by default
„Warning: mysql_connect() [function.mysql-connect]: User hircsardasql
already has more than 'max_user_connections' active connections in
/web/hircsarda/hircsarda.hu/wp-includes/wp-db.php on line 1515””
• USE max_user_connections, this will prevent a single app from using all
threads(max_connections)
 gdb -p $pid -ex "set max_connections=3000 --batch
4. MY.CNF – WAIT_TIMEOUT
9
 “mysqld actually permits max_connections+1 clients to connect. The extra
connection is reserved for use by accounts that have the SUPER privilege.”
 https://dev.mysql.com/doc/refman/5.7/en/too-many-connections.html
• GRANT ALL permission comes with SUPER which can write on instances with
read_only = ON
• You can use super-read-only in Percona Server >5.6
• https://www.percona.com/doc/percona-server/5.6/management/super_read_only.html
5. USER AUDIT
10
 Logical
• mysqldump
• mydumper
 Cold
• stop mysql, archive data files
 Snapshots
• LVM(performance overhead)
• EBS snapshots
 Hot or Online
• MySQL Enterprise backup(expensive)
• Percona XtraBackup
6. BACKUP
11
 Why EBS snapshots are great for backups/restore:
• easy to implement
• EC2 uses incremental snapshots
• Easy to provision multiple machines
 Cons
• EBSs are network drives, check the throughput limit for your instance
• (n disks * throughput)+other nw activity< bandwidth limit
• volumes are COLD in the beginning, penalty!
 http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs -ec2-config.html
6. BACKUP - EBS SNAPSHOTS
12
Warming up new 100GB EBS disks - m3.2xlarge EBS optimized instance
 http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs -prewarm.html
6. BACKUP - EBS SNAPSHOTS
Type Warmup Time Warmup Speed
SSD ‘io1’ PIOPS 3000 869s 124 MB/s
generic purpose ‘gp2’
SSD 300/3000
864s 124 MB/s
SSD ‘io1’ PIOPS 1500 1604s 66.8 MB/s
Magnetic ‘standard’ no
iops
4884s 22.0 MB/s
13
“If you access a piece of data that hasn't been loaded yet, the
volume immediately downloads the requested data from Amazon
S3, and then continues loading the rest of the volume's data in the
background. “
 http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSSnapshots.html
 EBS types:
• gp2 1TB 3.000 IOPS
• io1 1TB 20.000 IOPS
• magnetic 1TB
 Warming up the data on 2 threads:
355467264 bytes (355 MB) copied, 159.721 s, 2.2 MB/s
475004928 bytes (475 MB) copied, 159.601 s, 3.0 MB/s
 Warming up the data on 3 threads:
 360710144 bytes (361 MB) copied, 195.47 s, 1.8 MB/s
363855872 bytes (364 MB) copied, 195.47 s, 1.9 MB/s
360710144 bytes (361 MB) copied, 195.471 s, 1.8 MB/s
6. BACKUP - EBS SNAPSHOTS
14
 Warming up 20GB (or restore from a backup kept on a snapshot):
 4302.73 s, 5.0 MB/s = 71 minutes
 If we want to warm up a 500GB volume = ~ 30 hours!!!
6. BACKUP - RESTORE FROM EBS
15
 Online open source backup tool from Percona
• Parallel
• Compression
• Enryption
• Streaming
• Throttle
• Doesn’t work with streaming!
• Having multiple MyISAM needs longer period when Flush Tables With Read Lock
 S3 upload/download speed is pretty good:
innobackupex --user=root --password=password --stream=xbstream --
encrypt=AES256 --encrypt-key-file=keyfile --parallel=10 /tmp | pigz –p 2|pv –l
20M | aws s3 cp - s3://bucket/filename.gz
 Do you have (encrypted) offsite backup ?
6. BACKUP - PERCONA XRABACKUP
16
• Backups taken with Xtrabackup are consistent across databases
• Backups are not consistent across clusters (end time matters)
• Consistent restore requires point in time recovery
• mysqlbinlog supports --read-from-remote-server starting from MySQL 5.5
• expire_logs_days = 10 by default
6. BACKUP - MYSQLBINLOG
17
• Disable atime on the data partition
• Disable swap
• Allocate most of the RAM to MySQL
• This will make it the perfect candidate to kill for the OOM-killer
• tmp files goes to /tmp by default
• DDLs on big tables can consume it!
[mysqld]
open_files_limit = 10000
/etc/security/limits.conf:
* hard nofile 10000
* soft nofile 10000
7. OS
18
• “1 pageload = 1 bad query” can be deadly when aggregating a lot of data even on a
small table
 Monitor:
• pt-query-digest
• Anemometer
• Percona Monitoring and Management Query Analyzer
• Vividcortex
 Handle:
• pt-kill
• ProxySQL
• Memcached
8 - QUERIES
19
• INT: Most typical column types for Primary Keys
• UNSIGNED NOT NULL
• A rolled back TX still increases the AUTO_INCREMENT
 https://github.com/RickPizzi/pztools/blob/master/findmax.sh
9 SCHEMA – MAX INTEGER CHECK
20
 “In a Web environment where the clients are connecting from a Web server, a user
could use LOAD DATA LOCAL to read any files that the Web server process has read
access to (assuming that a user could run any command against the SQL server).”
 http://dev.mysql.com/doc/refman/5.6/en/load-data-local.html
 [root@hostdb~]# mysql -e "SHOW GLOBAL VARIABLES LIKE 'local_infile'"
 +---------------+-------+
 | Variable_name | Value |
 +---------------+-------+
 | local_infile | ON |
 +---------------+-------+
 [root@hostdb ~]# mysql -e "show grants for wordpress@%”
 GRANT USAGE ON *.* TO ’wordpress@'localhost' IDENTIFIED BY PASSWORD ‘xxx’
 GRANT SELECT, INSERT ON `wordpress`.* TO ’wordpress'@’%’
10 LOAD DATA LOCAL INFILE
21
 mysql> LOAD DATA LOCAL INFILE '/root/.aws/config' INTO TABLE `wp_comments`
(comment_content) ;
 Query OK, 5 rows affected, 2 warnings (0.00 sec)
 mysql> LOAD DATA LOCAL INFILE '/root/.my.cnf' INTO TABLE `wp_comments`
(comment_content) ;
 Query OK, 3 rows affected, 2 warnings (0.00 sec)
10 LOAD DATA LOCAL INFILE
select comment_content from wp_comments;
[..]
| [default]
| output = json
| region = us-west-2
| aws_access_key_id = AKIAxxxxxxxxx
| aws_secret_access_key = S4xxxxxxxxxxxxxxxxxx
| [client]
| user=root
| password=mysqlpassword
|
22
10 LOAD DATA LOCAL INFILE
23
QUESTIONS?

More Related Content

What's hot (20)

PPTX
Mysql data replication
Tuấn Ngô
 
PPT
Basic Knowledge on MySql Replication
Tasawr Interactive
 
PPT
High Availabiltity & Replica Sets with mongoDB
Gareth Davies
 
ODP
Nagios Conference 2014 - Troy Lea - Monitoring VMware Virtualization Using vMA
Nagios
 
PDF
Open Source SQL databases enters millions queries per second era
Sveta Smirnova
 
PPT
Intro to MySQL Master Slave Replication
satejsahu
 
PDF
MySQL High Availability Deep Dive
hastexo
 
KEY
Deployment Strategy
MongoDB
 
PDF
Intro ProxySQL
I Goo Lee
 
PPTX
Nagios Conference 2014 - Jeff Mendoza - Monitoring Microsoft Azure with Nagios
Nagios
 
PDF
10 Key MongoDB Performance Indicators
iammutex
 
PPTX
Elastic stack
Minsoo Jun
 
PDF
Dbdeployer
Giuseppe Maxia
 
PPTX
MongoDB Performance Tuning and Monitoring
MongoDB
 
PDF
Introduction of mesos persistent storage
Zhou Weitao
 
PDF
Elastic search 클러스터관리
HyeonSeok Choi
 
PPTX
Introduction To Apache Mesos
Joe Stein
 
PPTX
Containerized Data Persistence on Mesos
Joe Stein
 
PDF
Configuring MongoDB HA Replica Set on AWS EC2
ShepHertz
 
PPTX
MongoDB in Windows Azure - Evgeniy Maliy - Dnipropetrovsk MUG 140303
Victoria Malaya
 
Mysql data replication
Tuấn Ngô
 
Basic Knowledge on MySql Replication
Tasawr Interactive
 
High Availabiltity & Replica Sets with mongoDB
Gareth Davies
 
Nagios Conference 2014 - Troy Lea - Monitoring VMware Virtualization Using vMA
Nagios
 
Open Source SQL databases enters millions queries per second era
Sveta Smirnova
 
Intro to MySQL Master Slave Replication
satejsahu
 
MySQL High Availability Deep Dive
hastexo
 
Deployment Strategy
MongoDB
 
Intro ProxySQL
I Goo Lee
 
Nagios Conference 2014 - Jeff Mendoza - Monitoring Microsoft Azure with Nagios
Nagios
 
10 Key MongoDB Performance Indicators
iammutex
 
Elastic stack
Minsoo Jun
 
Dbdeployer
Giuseppe Maxia
 
MongoDB Performance Tuning and Monitoring
MongoDB
 
Introduction of mesos persistent storage
Zhou Weitao
 
Elastic search 클러스터관리
HyeonSeok Choi
 
Introduction To Apache Mesos
Joe Stein
 
Containerized Data Persistence on Mesos
Joe Stein
 
Configuring MongoDB HA Replica Set on AWS EC2
ShepHertz
 
MongoDB in Windows Azure - Evgeniy Maliy - Dnipropetrovsk MUG 140303
Victoria Malaya
 

Viewers also liked (11)

PDF
Introduction to monitoring
Janos Ruszo
 
PDF
Agile Fundamentals and Best Practices (with Trello)
Filippo Zanella
 
PDF
More mastering the art of indexing
Yoshinori Matsunobu
 
PDF
Des principes de la démarche DevOps à sa mise en oeuvre
Stephane Manciot
 
PDF
ProxySQL - High Performance and HA Proxy for MySQL
René Cannaò
 
PDF
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Jaime Crespo
 
PDF
Galera cluster for MySQL - Introduction Slides
Severalnines
 
PDF
DevOps avec Ansible et Docker
Stephane Manciot
 
PDF
How to Design Indexes, Really
Karwin Software Solutions LLC
 
PDF
Percona Live 2012PPT: MySQL Query optimization
mysqlops
 
PDF
Laracon Online: Grid and Flexbox
Rachel Andrew
 
Introduction to monitoring
Janos Ruszo
 
Agile Fundamentals and Best Practices (with Trello)
Filippo Zanella
 
More mastering the art of indexing
Yoshinori Matsunobu
 
Des principes de la démarche DevOps à sa mise en oeuvre
Stephane Manciot
 
ProxySQL - High Performance and HA Proxy for MySQL
René Cannaò
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Jaime Crespo
 
Galera cluster for MySQL - Introduction Slides
Severalnines
 
DevOps avec Ansible et Docker
Stephane Manciot
 
How to Design Indexes, Really
Karwin Software Solutions LLC
 
Percona Live 2012PPT: MySQL Query optimization
mysqlops
 
Laracon Online: Grid and Flexbox
Rachel Andrew
 
Ad

Similar to How (not) to kill your MySQL infrastructure (20)

PPTX
Infrastructure review - Shining a light on the Black Box
Miklos Szel
 
PDF
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
Aurimas Mikalauskas
 
PDF
MySQL 8.0 InnoDB Cluster demo
Keith Hollman
 
PDF
Loadays MySQL
lefredbe
 
PDF
MySQL 8.0 InnoDB Cluster - Easiest Tutorial
Frederic Descamps
 
PDF
Basic MySQL Troubleshooting for Oracle Database Administrators
Sveta Smirnova
 
PDF
Buytaert kris my_sql-pacemaker
kuchinskaya
 
PDF
MySQL Performance Tuning London Meetup June 2017
Ivan Zoratti
 
PDF
How to operate MySQL InnoDB Cluster with MySQL Shell
Frederic Descamps
 
PDF
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
Kenny Gryp
 
PDF
MySQL Manchester TT - Performance Tuning
Mark Swarbrick
 
PDF
MySQL Backup and Security Best Practices
Lenz Grimmer
 
PDF
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
Frederic Descamps
 
PPTX
Finding an unusual cause of max_user_connections in MySQL
Olivier Doucet
 
PDF
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
Dave Stokes
 
PDF
MySQL NoSQL APIs
Morgan Tocker
 
PDF
20190817 coscup-oracle my sql innodb cluster sharing
Ivan Ma
 
PDF
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
Kenny Gryp
 
PDF
OSDC 2017 | Lessons from database failures by Colin Charles
NETWAYS
 
PDF
The Proper Care and Feeding of MySQL Databases
Dave Stokes
 
Infrastructure review - Shining a light on the Black Box
Miklos Szel
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
Aurimas Mikalauskas
 
MySQL 8.0 InnoDB Cluster demo
Keith Hollman
 
Loadays MySQL
lefredbe
 
MySQL 8.0 InnoDB Cluster - Easiest Tutorial
Frederic Descamps
 
Basic MySQL Troubleshooting for Oracle Database Administrators
Sveta Smirnova
 
Buytaert kris my_sql-pacemaker
kuchinskaya
 
MySQL Performance Tuning London Meetup June 2017
Ivan Zoratti
 
How to operate MySQL InnoDB Cluster with MySQL Shell
Frederic Descamps
 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
Kenny Gryp
 
MySQL Manchester TT - Performance Tuning
Mark Swarbrick
 
MySQL Backup and Security Best Practices
Lenz Grimmer
 
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
Frederic Descamps
 
Finding an unusual cause of max_user_connections in MySQL
Olivier Doucet
 
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
Dave Stokes
 
MySQL NoSQL APIs
Morgan Tocker
 
20190817 coscup-oracle my sql innodb cluster sharing
Ivan Ma
 
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
Kenny Gryp
 
OSDC 2017 | Lessons from database failures by Colin Charles
NETWAYS
 
The Proper Care and Feeding of MySQL Databases
Dave Stokes
 
Ad

Recently uploaded (20)

PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PDF
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
PPTX
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PPT
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Design Thinking basics for Engineers.pdf
CMR University
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 

How (not) to kill your MySQL infrastructure

  • 1. HOW (NOT) TO KILL YOUR MYSQL INFRASTRUCTURE Based on true stories
  • 2. 2 • Miklos ‘Mukka’ Szel • From Hungary • Started using Linux in 1997 and MySQL in 2000, used to be a backend developer • Worked for Own Startup, ISP, Walt Disney(ESPN,Cricinfo), PalominoDB/Pythian • Freelance Consultant since 2015 - Edmodo /ME
  • 3. 3 Ansible: - name: Install MySQL-Oracle Server yum: pkg={{ item }} state=present with_items: - MySQL-server - MySQL-client Centos/Redhat: yum install MySQL-server Debian/Ubuntu: apt-get install percona-server-server-5.6 1. VERSION MISMATCH - SOFTWARE
  • 4. 4 ./pt-slave-find --host 10.77.3.181 -u root--ask-pass Enter password: 10.77.24.181 Version 5.6.32-78.1-log Server ID 134 Uptime 318+06:01:55 (started 2015-11-19T02:42:03) Replication Is not a slave, has 1 slaves connected, is not read_only Filters Binary logging MIXED Slave status Slave mode STRICT InnoDB version 5.6.32-78.1 +- 10.77.25.17 Version 5.6.27-75.0-log Server ID 143 Uptime 167+18:21:03 (started 2016 -04-17T14:22:55) Replication Is a slave, has 0 slaves connected, is read_only Filters Binary logging MIXED Slave status 0 seconds behind, running, no errors Slave mode STRICT Auto-increment increment 2, offset 1 InnoDB version 5.6.27-75.0 1. VERSION MISMATCH - SOFTWARE
  • 5. 5 • Monitoring • Check the process list on every server • Scan for port  nmap -p 3306 –sV 10.77.3.0/24  Nmap scan report for 10.77.3.238  Host is up (0.00087s latency).  PORT STATE SERVICE VERSION  3306/tcp open mysql MySQL 5.6.27-75.0-log 1. VERSION MISMATCH - SOFTWARE
  • 6. 6 • Between config file and runtime variables • Between servers in the same replication chain ./pt-config-diff /etc/my.cnf h=localhost 3 config differences Variable /etc/my.cnf c1-adhoc4-i.us-west2 ======================================== innodb_thread_concurrency 0 4 wait_timeout 600 3600 read_only ON OFF https://www.percona.com/doc/percona-toolkit/2.2/pt-config-diff.html 2. VERSION MISMATCH - CONFIG
  • 7. 7 • Don’t use methods like removing dots from ip addresses • 10.77.12.3 (1077123) • 10.77.1.23 (1077123) • MySQL truncates the server_id if it’s bigger than the max value for an INT(4294967295) • 192.168.111.222 (192168111222 -> 4294967295) • 192.168.222.222 (192168222222 -> 4294967295) • 4508354421957495439 -> 4294967295 • 12354356476576 -> 4294967295 3. MY.CNF – SERVER_ID
  • 8. 8 • Wait_timeout 28800 by default „Warning: mysql_connect() [function.mysql-connect]: User hircsardasql already has more than 'max_user_connections' active connections in /web/hircsarda/hircsarda.hu/wp-includes/wp-db.php on line 1515”” • USE max_user_connections, this will prevent a single app from using all threads(max_connections)  gdb -p $pid -ex "set max_connections=3000 --batch 4. MY.CNF – WAIT_TIMEOUT
  • 9. 9  “mysqld actually permits max_connections+1 clients to connect. The extra connection is reserved for use by accounts that have the SUPER privilege.”  https://dev.mysql.com/doc/refman/5.7/en/too-many-connections.html • GRANT ALL permission comes with SUPER which can write on instances with read_only = ON • You can use super-read-only in Percona Server >5.6 • https://www.percona.com/doc/percona-server/5.6/management/super_read_only.html 5. USER AUDIT
  • 10. 10  Logical • mysqldump • mydumper  Cold • stop mysql, archive data files  Snapshots • LVM(performance overhead) • EBS snapshots  Hot or Online • MySQL Enterprise backup(expensive) • Percona XtraBackup 6. BACKUP
  • 11. 11  Why EBS snapshots are great for backups/restore: • easy to implement • EC2 uses incremental snapshots • Easy to provision multiple machines  Cons • EBSs are network drives, check the throughput limit for your instance • (n disks * throughput)+other nw activity< bandwidth limit • volumes are COLD in the beginning, penalty!  http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs -ec2-config.html 6. BACKUP - EBS SNAPSHOTS
  • 12. 12 Warming up new 100GB EBS disks - m3.2xlarge EBS optimized instance  http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs -prewarm.html 6. BACKUP - EBS SNAPSHOTS Type Warmup Time Warmup Speed SSD ‘io1’ PIOPS 3000 869s 124 MB/s generic purpose ‘gp2’ SSD 300/3000 864s 124 MB/s SSD ‘io1’ PIOPS 1500 1604s 66.8 MB/s Magnetic ‘standard’ no iops 4884s 22.0 MB/s
  • 13. 13 “If you access a piece of data that hasn't been loaded yet, the volume immediately downloads the requested data from Amazon S3, and then continues loading the rest of the volume's data in the background. “  http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSSnapshots.html  EBS types: • gp2 1TB 3.000 IOPS • io1 1TB 20.000 IOPS • magnetic 1TB  Warming up the data on 2 threads: 355467264 bytes (355 MB) copied, 159.721 s, 2.2 MB/s 475004928 bytes (475 MB) copied, 159.601 s, 3.0 MB/s  Warming up the data on 3 threads:  360710144 bytes (361 MB) copied, 195.47 s, 1.8 MB/s 363855872 bytes (364 MB) copied, 195.47 s, 1.9 MB/s 360710144 bytes (361 MB) copied, 195.471 s, 1.8 MB/s 6. BACKUP - EBS SNAPSHOTS
  • 14. 14  Warming up 20GB (or restore from a backup kept on a snapshot):  4302.73 s, 5.0 MB/s = 71 minutes  If we want to warm up a 500GB volume = ~ 30 hours!!! 6. BACKUP - RESTORE FROM EBS
  • 15. 15  Online open source backup tool from Percona • Parallel • Compression • Enryption • Streaming • Throttle • Doesn’t work with streaming! • Having multiple MyISAM needs longer period when Flush Tables With Read Lock  S3 upload/download speed is pretty good: innobackupex --user=root --password=password --stream=xbstream -- encrypt=AES256 --encrypt-key-file=keyfile --parallel=10 /tmp | pigz –p 2|pv –l 20M | aws s3 cp - s3://bucket/filename.gz  Do you have (encrypted) offsite backup ? 6. BACKUP - PERCONA XRABACKUP
  • 16. 16 • Backups taken with Xtrabackup are consistent across databases • Backups are not consistent across clusters (end time matters) • Consistent restore requires point in time recovery • mysqlbinlog supports --read-from-remote-server starting from MySQL 5.5 • expire_logs_days = 10 by default 6. BACKUP - MYSQLBINLOG
  • 17. 17 • Disable atime on the data partition • Disable swap • Allocate most of the RAM to MySQL • This will make it the perfect candidate to kill for the OOM-killer • tmp files goes to /tmp by default • DDLs on big tables can consume it! [mysqld] open_files_limit = 10000 /etc/security/limits.conf: * hard nofile 10000 * soft nofile 10000 7. OS
  • 18. 18 • “1 pageload = 1 bad query” can be deadly when aggregating a lot of data even on a small table  Monitor: • pt-query-digest • Anemometer • Percona Monitoring and Management Query Analyzer • Vividcortex  Handle: • pt-kill • ProxySQL • Memcached 8 - QUERIES
  • 19. 19 • INT: Most typical column types for Primary Keys • UNSIGNED NOT NULL • A rolled back TX still increases the AUTO_INCREMENT  https://github.com/RickPizzi/pztools/blob/master/findmax.sh 9 SCHEMA – MAX INTEGER CHECK
  • 20. 20  “In a Web environment where the clients are connecting from a Web server, a user could use LOAD DATA LOCAL to read any files that the Web server process has read access to (assuming that a user could run any command against the SQL server).”  http://dev.mysql.com/doc/refman/5.6/en/load-data-local.html  [root@hostdb~]# mysql -e "SHOW GLOBAL VARIABLES LIKE 'local_infile'"  +---------------+-------+  | Variable_name | Value |  +---------------+-------+  | local_infile | ON |  +---------------+-------+  [root@hostdb ~]# mysql -e "show grants for wordpress@%”  GRANT USAGE ON *.* TO ’wordpress@'localhost' IDENTIFIED BY PASSWORD ‘xxx’  GRANT SELECT, INSERT ON `wordpress`.* TO ’wordpress'@’%’ 10 LOAD DATA LOCAL INFILE
  • 21. 21  mysql> LOAD DATA LOCAL INFILE '/root/.aws/config' INTO TABLE `wp_comments` (comment_content) ;  Query OK, 5 rows affected, 2 warnings (0.00 sec)  mysql> LOAD DATA LOCAL INFILE '/root/.my.cnf' INTO TABLE `wp_comments` (comment_content) ;  Query OK, 3 rows affected, 2 warnings (0.00 sec) 10 LOAD DATA LOCAL INFILE select comment_content from wp_comments; [..] | [default] | output = json | region = us-west-2 | aws_access_key_id = AKIAxxxxxxxxx | aws_secret_access_key = S4xxxxxxxxxxxxxxxxxx | [client] | user=root | password=mysqlpassword |
  • 22. 22 10 LOAD DATA LOCAL INFILE