SlideShare a Scribd company logo
SELECT RAND() FROM 
MYSQL_BITS 
devops meetup - Toronto 
1 of 35
Collecting email addresses 
meOw@email.com 
meow@email.com 
MEOW@email.com 
!
Let’s use a function ! 
mysql> explain SELECT id FROM users WHERE LOWER(email) = 
'lucas@uken.com' G! 
*************************** 1. row 
***************************! 
id: 1! 
select_type: SIMPLE! 
table: users! 
type: index! 
possible_keys: NULL! 
key: uu! 
key_len: 302! 
ref: NULL! 
rows: 4000! 
Extra: Using where; Using index! 
1 row in set (0.00 sec)
Collation Now you have N problems 
! 
Default: utf8_general_ci 
! 
select * from users where email='lucas@uken.com' 
+----------------+ 
| LUCAS@uken.com | 
| LuCaS@uken.com | 
+----------------+
And it gets better.. 
mysql> select * from users where email='LUCAS@uken.com';! 
+-----+-----------------+! 
| id | email |! 
+-----+-----------------+! 
| 1 | LUCAS@uken.com |! 
| 8 | LuCaS@uken.com |! 
| 109 | lücas@uken.com |! 
+-----+-----------------+
Just fix it 
SELECT * FROM users WHERE BINARY email='LUCAS@uken.com';! 
! 
+----+----------------+! 
| id | email |! 
+----+----------------+! 
| 1 | LUCAS@uken.com |! 
+----+----------------+
Stop the world 
Fix the app (settle on lowercase/uppercase), clean up all records 
! 
UPDATE users SET email = LOWER(email)! 
! 
Add unique index 
! 
CREATE UNIQUE INDEX unique_emails ON users(email)
Generating API Keys 
Just make sure they are unique
I got this ! 
CREATE TABLE apikeys(apikey BINARY(36) NOT 
NULL PRIMARY KEY);! 
! 
INSERT INTO apikeys(apikey) 
VALUES(UUID());! 
+--------------------------------------+! 
| apikey |! 
| 3d0e1678-ffce-11e2-ac86-18576e236284 |! 
+--------------------------------------+ 
unique != unpredictable
Why... 
RFC 4122 (128bit) timestamp, dce, md5, mac, random 
! 
SELECT UUID(),UUID(),UUID() G! 
*************************** 1. row 
************************! 
UUID(): 3278447a-ffd0-11e2-ac86-18576e236284! 
UUID(): 3278448e-ffd0-11e2-ac86-18576e236284! 
UUID(): 3278448f-ffd0-11e2-ac86-18576e236284
Just fix it 
>>> import uuid! 
>>> uuid.uuid4()! 
UUID('92d0b870-2336-497b-b310- 
e48bdda5938c')! 
>>> uuid.uuid4()! 
UUID('e3116e9c-318c-4ec3-91c1-64fae7990007')! 
! 
! 
#uuid1 = time based! 
#uuid3 = md5 namespace! 
#uuid4 = random! 
#uuid5 = sha1 namespace
Make it meaningful 
h = 
hmac.new('supersecret',digestmod=hashlib.sha1)! 
h.update('192.168.0.1') # ip for this api key! 
print(h.hexdigest())! 
! 
7b8a2ac1bf1e6e1dfae65f957174d830ccb83c8c
Primary keys 
I like uuids and I cannot lie...
It’s a thing ! 
CREATE TABLE apikeys(apikey BINARY(36) NOT 
NULL PRIMARY KEY);! 
! 
● Storage size 
● last_insert_id (it is based on auto increment fields) 
● Breaks ORMs (ex: node-orm / ActiveRecord) 
● 'PRIMARY KEY' implies 'UNIQUE' key.
http://kccoder.com/mysql/uuid-vs-int-insert-performance/
Partitions 
but..but... shards are webscale!
*Most storage engines MyISAM, InnoDB, Archive 
! 
CREATE TABLE part (id INT PRIMARY KEY 
AUTO_INCREMENT)! 
PARTITION BY RANGE (id) (! 
PARTITION p0 VALUES LESS THAN (10),! 
PARTITION p3 VALUES LESS THAN MAXVALUE);! 
! Integers: dates, ranges, server_id 
Strings get hashed: tags, groups
Trying it out 
EXPLAIN PARTITIONS SELECT * FROM part WHERE id < 30 
G! 
partitions: p0,p1! 
type: range! 
rows: 29! 
! 
EXPLAIN PARTITIONS SELECT * FROM part WHERE id < 8 
G! 
table: part! 
partitions: p0! 
type: range! 
rows: 7
Thank you !

More Related Content

What's hot

Apache Cassandra - Data modelling
Apache Cassandra - Data modellingApache Cassandra - Data modelling
Apache Cassandra - Data modelling
Alex Thompson
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
Stanley Huang
 
Psycopg2 postgres python DDL Operaytions (select , Insert , update, create ta...
Psycopg2 postgres python DDL Operaytions (select , Insert , update, create ta...Psycopg2 postgres python DDL Operaytions (select , Insert , update, create ta...
Psycopg2 postgres python DDL Operaytions (select , Insert , update, create ta...
sachin kumar
 
Topologi Jaringan untuk Ujian Nasional Berbasis Komputer 2016
Topologi Jaringan untuk Ujian Nasional Berbasis Komputer 2016Topologi Jaringan untuk Ujian Nasional Berbasis Komputer 2016
Topologi Jaringan untuk Ujian Nasional Berbasis Komputer 2016
Chusnul Labib
 
My sq ltutorial
My sq ltutorialMy sq ltutorial
My sq ltutorial
Marko Ancev
 
Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance
Alexey Ermakov
 
Scaling IO-bound microservices
Scaling IO-bound microservicesScaling IO-bound microservices
Scaling IO-bound microservices
Salo Shp
 
ES2015 and React
ES2015 and ReactES2015 and React
ES2015 and React
Stepan Parunashvili
 
Indexing & query optimization
Indexing & query optimizationIndexing & query optimization
Indexing & query optimization
Jared Rosoff
 
제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀
제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀
제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀
EXEM
 

What's hot (10)

Apache Cassandra - Data modelling
Apache Cassandra - Data modellingApache Cassandra - Data modelling
Apache Cassandra - Data modelling
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
 
Psycopg2 postgres python DDL Operaytions (select , Insert , update, create ta...
Psycopg2 postgres python DDL Operaytions (select , Insert , update, create ta...Psycopg2 postgres python DDL Operaytions (select , Insert , update, create ta...
Psycopg2 postgres python DDL Operaytions (select , Insert , update, create ta...
 
Topologi Jaringan untuk Ujian Nasional Berbasis Komputer 2016
Topologi Jaringan untuk Ujian Nasional Berbasis Komputer 2016Topologi Jaringan untuk Ujian Nasional Berbasis Komputer 2016
Topologi Jaringan untuk Ujian Nasional Berbasis Komputer 2016
 
My sq ltutorial
My sq ltutorialMy sq ltutorial
My sq ltutorial
 
Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance
 
Scaling IO-bound microservices
Scaling IO-bound microservicesScaling IO-bound microservices
Scaling IO-bound microservices
 
ES2015 and React
ES2015 and ReactES2015 and React
ES2015 and React
 
Indexing & query optimization
Indexing & query optimizationIndexing & query optimization
Indexing & query optimization
 
제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀
제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀
제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀
 

Similar to Mysql devops-to

Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part III
Alkin Tezuysal
 
Quick Wins
Quick WinsQuick Wins
Quick Wins
HighLoad2009
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
Mauro Pagano
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
Sveta Smirnova
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query Tuning
Sveta Smirnova
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
Sveta Smirnova
 
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 specVoxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
Voxxed Days Thessaloniki
 
Finding SQL execution outliers
Finding SQL execution outliersFinding SQL execution outliers
Finding SQL execution outliers
Maxym Kharchenko
 
Undelete (and more) rows from the binary log
Undelete (and more) rows from the binary logUndelete (and more) rows from the binary log
Undelete (and more) rows from the binary log
Frederic Descamps
 
Reverse eningeering
Reverse eningeeringReverse eningeering
Reverse eningeering
Kent Huang
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
Connor McDonald
 
10x Performance Improvements
10x Performance Improvements10x Performance Improvements
10x Performance Improvements
Ronald Bradford
 
10x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp0210x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp02
promethius
 
5 Cool Things About SQL
5 Cool Things About SQL5 Cool Things About SQL
5 Cool Things About SQL
Connor McDonald
 
SAV
SAVSAV
Windows Debugging with WinDbg
Windows Debugging with WinDbgWindows Debugging with WinDbg
Windows Debugging with WinDbg
Arno Huetter
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
DefconRussia
 
Database management system file
Database management system fileDatabase management system file
Database management system file
Ankit Dixit
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
Connor McDonald
 
neutron测试例子
neutron测试例子neutron测试例子
neutron测试例子
Jesse 郑晓明
 

Similar to Mysql devops-to (20)

Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part III
 
Quick Wins
Quick WinsQuick Wins
Quick Wins
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query Tuning
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
 
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 specVoxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
 
Finding SQL execution outliers
Finding SQL execution outliersFinding SQL execution outliers
Finding SQL execution outliers
 
Undelete (and more) rows from the binary log
Undelete (and more) rows from the binary logUndelete (and more) rows from the binary log
Undelete (and more) rows from the binary log
 
Reverse eningeering
Reverse eningeeringReverse eningeering
Reverse eningeering
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
10x Performance Improvements
10x Performance Improvements10x Performance Improvements
10x Performance Improvements
 
10x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp0210x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp02
 
5 Cool Things About SQL
5 Cool Things About SQL5 Cool Things About SQL
5 Cool Things About SQL
 
SAV
SAVSAV
SAV
 
Windows Debugging with WinDbg
Windows Debugging with WinDbgWindows Debugging with WinDbg
Windows Debugging with WinDbg
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
 
Database management system file
Database management system fileDatabase management system file
Database management system file
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
 
neutron测试例子
neutron测试例子neutron测试例子
neutron测试例子
 

Recently uploaded

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 

Recently uploaded (20)

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 

Mysql devops-to

  • 1. SELECT RAND() FROM MYSQL_BITS devops meetup - Toronto 1 of 35
  • 2. Collecting email addresses meOw@email.com meow@email.com MEOW@email.com !
  • 3. Let’s use a function ! mysql> explain SELECT id FROM users WHERE LOWER(email) = 'lucas@uken.com' G! *************************** 1. row ***************************! id: 1! select_type: SIMPLE! table: users! type: index! possible_keys: NULL! key: uu! key_len: 302! ref: NULL! rows: 4000! Extra: Using where; Using index! 1 row in set (0.00 sec)
  • 4. Collation Now you have N problems ! Default: utf8_general_ci ! select * from users where email='lucas@uken.com' +----------------+ | LUCAS@uken.com | | LuCaS@uken.com | +----------------+
  • 5. And it gets better.. mysql> select * from users where email='LUCAS@uken.com';! +-----+-----------------+! | id | email |! +-----+-----------------+! | 1 | LUCAS@uken.com |! | 8 | LuCaS@uken.com |! | 109 | lücas@uken.com |! +-----+-----------------+
  • 6. Just fix it SELECT * FROM users WHERE BINARY email='LUCAS@uken.com';! ! +----+----------------+! | id | email |! +----+----------------+! | 1 | LUCAS@uken.com |! +----+----------------+
  • 7. Stop the world Fix the app (settle on lowercase/uppercase), clean up all records ! UPDATE users SET email = LOWER(email)! ! Add unique index ! CREATE UNIQUE INDEX unique_emails ON users(email)
  • 8. Generating API Keys Just make sure they are unique
  • 9. I got this ! CREATE TABLE apikeys(apikey BINARY(36) NOT NULL PRIMARY KEY);! ! INSERT INTO apikeys(apikey) VALUES(UUID());! +--------------------------------------+! | apikey |! | 3d0e1678-ffce-11e2-ac86-18576e236284 |! +--------------------------------------+ unique != unpredictable
  • 10. Why... RFC 4122 (128bit) timestamp, dce, md5, mac, random ! SELECT UUID(),UUID(),UUID() G! *************************** 1. row ************************! UUID(): 3278447a-ffd0-11e2-ac86-18576e236284! UUID(): 3278448e-ffd0-11e2-ac86-18576e236284! UUID(): 3278448f-ffd0-11e2-ac86-18576e236284
  • 11. Just fix it >>> import uuid! >>> uuid.uuid4()! UUID('92d0b870-2336-497b-b310- e48bdda5938c')! >>> uuid.uuid4()! UUID('e3116e9c-318c-4ec3-91c1-64fae7990007')! ! ! #uuid1 = time based! #uuid3 = md5 namespace! #uuid4 = random! #uuid5 = sha1 namespace
  • 12. Make it meaningful h = hmac.new('supersecret',digestmod=hashlib.sha1)! h.update('192.168.0.1') # ip for this api key! print(h.hexdigest())! ! 7b8a2ac1bf1e6e1dfae65f957174d830ccb83c8c
  • 13. Primary keys I like uuids and I cannot lie...
  • 14. It’s a thing ! CREATE TABLE apikeys(apikey BINARY(36) NOT NULL PRIMARY KEY);! ! ● Storage size ● last_insert_id (it is based on auto increment fields) ● Breaks ORMs (ex: node-orm / ActiveRecord) ● 'PRIMARY KEY' implies 'UNIQUE' key.
  • 17. *Most storage engines MyISAM, InnoDB, Archive ! CREATE TABLE part (id INT PRIMARY KEY AUTO_INCREMENT)! PARTITION BY RANGE (id) (! PARTITION p0 VALUES LESS THAN (10),! PARTITION p3 VALUES LESS THAN MAXVALUE);! ! Integers: dates, ranges, server_id Strings get hashed: tags, groups
  • 18. Trying it out EXPLAIN PARTITIONS SELECT * FROM part WHERE id < 30 G! partitions: p0,p1! type: range! rows: 29! ! EXPLAIN PARTITIONS SELECT * FROM part WHERE id < 8 G! table: part! partitions: p0! type: range! rows: 7