SlideShare una empresa de Scribd logo
1 de 93
The VP R&D Open Seminar




     MySQL Crash Course
    From basics to experts
           mokplan@gmail.com
  http://top-performance.blogspot.com
The VP R&D Open Seminar




WHY WE CHOSE MYSQL?


   http://top-performance.blogspot.com
Who is Using MySQL?




3
    http://top-performance.blogspot.com
Who is Behind MySQL




http://top-performance.blogspot.com
What MySQL is Made of?




5
                              http://top-performance.blogspot.com
    http://dev.mysql.com/tech-resources/articles/mysql_5.0_psea1.html
MySQL Limitations




    50-150M Records/Table
    50-5000 SELECT Statements/Second

6
         http://top-performance.blogspot.com
Why Do I Care?
    From 0 to 100 (US mass adaptation)
      Phone:            100 yrs
      Radio:            40 yrs
      TV:               30 yrs
      Mobile:           20 yrs
      Internet:         10 yrs
      Facebook:         2 yrs



7
                http://top-performance.blogspot.com
100K New Users/Week




8
    http://top-performance.blogspot.com
The VP R&D Open Seminar




WHAT MYSQL IS MADE OF?


   http://top-performance.blogspot.com
MySQL Structure
Daemon
/var/lib/mysql
  ibdata1
  ib_logfile0, Ib_logfile1
  /mysql
  /database
  /performance_schema
/etc/my.cnf


       http://top-performance.blogspot.com
What to Install
wget mysql_package
yum –y localinstall mysql_package

The Packages:
  Devel+Client+Server
  Relevant platform (x86/x64)
  Relevant operating system




       http://top-performance.blogspot.com
MySQL Installation




http://top-performance.blogspot.com
The VP R&D Open Seminar




DATABASE LOGICAL DESIGN
(OR ERD)

   http://top-performance.blogspot.com
Instances, Schemas and inside information




      http://top-performance.blogspot.com
1:Many




schoolId:                        schoolId:
Primary Key                      Foreign Key


http://top-performance.blogspot.com
Many:Many




?:                                       ?:
Primary Key                              Foreign Key


        http://top-performance.blogspot.com
Many:Many in Practice




testId:             testId,               studentId:
Primary Key         studentId:            Primary Key
                    Foreign Key

        http://top-performance.blogspot.com
Design a Student Information System ERD




      http://top-performance.blogspot.com
The VP R&D Open Seminar




FROM ERD TO A DATABASE


   http://top-performance.blogspot.com
Connect to the Database




http://top-performance.blogspot.com
Create a Schema/Database




http://top-performance.blogspot.com
Create a Table




http://top-performance.blogspot.com
Implement the a Student Information System ERD




       http://top-performance.blogspot.com
The VP R&D Open Seminar




SQL: DDL


    http://top-performance.blogspot.com
Databases Manipulation
SHOW DATABASES;
CREATE DATABASE mydb;
DROP DATABASE mydb;
USE mydb;




     http://top-performance.blogspot.com
Tables Manipulation
SHOW TABLES;
CREATE TABLE users (
id int,
INDEX users_id (id)
);
DROP TABLE users;
ALTER TABLE users ADD INDEX IX_id (id);
ALTER TABLE users DROP INDEX IX_id;


      http://top-performance.blogspot.com
The VP R&D Open Seminar




SQL: DML


   http://top-performance.blogspot.com
SELECT
SELECT table.field, table.*
FROM        table
WHERE table.field = 123
ORDER BY field1, field2 DESC




      http://top-performance.blogspot.com
SELECT + Join
SELECT     c.*, u.*
FROM       classes c
  INNER JOIN users u
  ON c.teacherId = u.id




      http://top-performance.blogspot.com
LEFT JOIN




http://top-performance.blogspot.com
GROUP BY
SELECT          gender, count(id)
FROM            users
WHERE       gender = ‘M’
GROUP BY        gender
HAVING          count(id) > 10




     http://top-performance.blogspot.com
UNION
SELECT      id
FROM        users
WHERE       gender = ‘M’
UNION ALL
SELECT      id
FROM        users
WHERE       gender = ‘F’
ORDER BY    id;

     http://top-performance.blogspot.com
UPDATE
UPDATE      users
SET         gender = ‘M’
WHERE       gender IS NULL;




     http://top-performance.blogspot.com
INSERT
INSERT INTO        users (gender)
VALUES      (‘M’);

INSERT INTO         users (gender)
SELECT              gender
FROM                users
WHERE               gender = ‘M’;


       http://top-performance.blogspot.com
DELETE
DELETE
FROM       users
WHERE      gender = ‘M’;




    http://top-performance.blogspot.com
The VP R&D Open Seminar




MySQL Authentication and Authorization

SECURITY


         http://top-performance.blogspot.com
Root User
First Time
  mysqladmin -u root password NEWPASSWORD
Nth Time
  mysqladmin -u root -p'oldpassword' password
  newpass
How to enter
  Mysql –uuser_name –ppassword –D
  database_name
  -h host_name/ip -A

       http://top-performance.blogspot.com
Users Table
mysql> SELECT * FROM mysql.user limit 1G
*************************** 1. row ***************************
Host: localhost
User: root
Password: *4FB5C598BC3FF56E262F863A715F8CB2976A9C69
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
….
1 row in set (0.00 sec)


          http://top-performance.blogspot.com
Create a Users and Provide Permissions
-- Create a user w/ password
CREATE USER 'readonly'@'%' IDENTIFIED BY
‘sakexkas';
-- Grant Permissions
GRANT select ON my_db.* to 'readonly'@'%';
GRANT ALL PRIVILEGES ON *.* to
‘master_user’@’%’ WITH GRANT OPTION;
FLUSH PRIVILEGES;

-- Beware of too complex passwords


       http://top-performance.blogspot.com
The VP R&D Open Seminar




MYSQL AND LINUX ISSUES


    http://top-performance.blogspot.com
Built in Linux Security Measures
IP TABLES
   sudo /etc/init.d/iptables stop
   sudo yum –y remove iptables
   Configure the relevant rules
SELinux
   sudo echo 0 > /selinux/enforce
   vi /etc/selinux/config: SELINUX=enforcing  SELINUX=disabled
Files Limit (Table Partitioning)
   /etc/security/limits.conf
      mysql soft nofile 8192
      mysql hard nofile 8192
   my.cnf:
      open_files_limit = 8192



             http://top-performance.blogspot.com
Disk Resizing
http://top-
performance.blogspot.com/2012/02/do-you-
need-more-disk-space-for-mysql.html




      http://top-performance.blogspot.com
Create a Master/Slave configuration




     http://top-performance.blogspot.com
The VP R&D Open Seminar




HIGH AVAILABILITY
ARCHITECTURES

    http://top-performance.blogspot.com
Master/Slave




http://top-performance.blogspot.com
Master/Master




          ?
http://top-performance.blogspot.com
Show Status (1)
mysql> show slave statusG
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.12.12.167
Master_User: repl
Master_Port: 3306
Connect_Retry: 60

Master_Log_File: master.000094
Read_Master_Log_Pos: 167250867
Relay_Log_File: mysqld-relay-bin.000137
Relay_Log_Pos: 167251010

Relay_Master_Log_File: master.000094
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table: mysql.%,information_schema.%




                             http://top-performance.blogspot.com
Show Status (2)
Last_Errno: 0
Last_Error:
Skip_Counter: 0

Exec_Master_Log_Pos: 167250867
Relay_Log_Space: 167251310
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.02 sec)




                           http://top-performance.blogspot.com
Skip
DON’T DO THAT unless you have to!
The Process:
 STOP SLAVE;
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER =
 1;
 START SLAVE;
 SHOW SLAVE STATUSG




     http://top-performance.blogspot.com
How to Implement?
Stop a Master and record position
Copy a Master (instance/disk) to a Slave
Start the Master
Change slave server-id
SET MASTER HOST …
START SLAVE
Verify
Or…
http://top-performance.blogspot.co.il/2012/03/how-to-
setup-mysql-replication-in-11.html


        http://top-performance.blogspot.com
Create a Master/Slave configuration




     http://top-performance.blogspot.com
The VP R&D Open Seminar




SCALE-ABLE ARCHITECTURES


   http://top-performance.blogspot.com
Do You Remember?




53
     http://top-performance.blogspot.com
Strategy A: Sharding




54
     http://top-performance.blogspot.com
Strategy B: In Memory Databases




55
       http://top-performance.blogspot.com
700 Inserts/Sec



                                             In Memory Engine

                                             3000 Inserts/Sec




 Amazon AWS

 Standard                                    InnoDB Engine

 Large Instance                              700 Inserts/Sec




56
                  http://top-performance.blogspot.com
IMDB - Implementation




57
     http://top-performance.blogspot.com
Lessons
     Cache:             MySQL IMDB
     HA:                MySQL Replication
     Persistence:       Periodic 5min Batch
     Scalability:       Sharding

     4 Bill Req/Day using 25 machines (2000/s)




58
           http://top-performance.blogspot.com
Strategy C: MapReduce




59
     http://top-performance.blogspot.com
Strategy D: NoSQL
      insert
      get
        multiget
      remove
      truncate




                                   <Key, Value>
 http://wiki.apache.org/cassandra/API




60
                           http://top-performance.blogspot.com
When Should I Choose NoSQL?

     Eventually Consistent
     Document Store
     Key Value




                                http://guyharrison.squarespace.com/blog/tag/nosql




61
           http://top-performance.blogspot.com
Sharding Again




62
     http://top-performance.blogspot.com
Vertical Sharding




63
     http://top-performance.blogspot.com
Horizontal Sharding
     Static Hashing
     Complex growth                              Mod 10 = 0

                                                 Mod 10 = 1
     Simple
                                                 Mod 10 = 2

                                                 Mod 10 = 3

                                                 Mod 10 = 4

                                                 Mod 10 = 5

                                                 Mod 10 = 6

                                                 Mod 10 = 7

                                                 Mod 10 = 8

                                                 Mod 10 = 9



64
           http://top-performance.blogspot.com
Horizontal Sharding
     Key locations are defined in a directory
     Simple growth
     Directory is SPOF




65
            http://top-performance.blogspot.com
Horizontal Sharding
      Static Hashing with Directory Mapping
       Simple Growth
       Small Directory still SPOF




     Mod 1000 = 4


66
              http://top-performance.blogspot.com
Horizontal Sharding
     Each key signed by DB#
     generated on creation
     Simple growth
     New key generation is SPOF




67
           http://top-performance.blogspot.com
Limitations: Reporting




68
     http://top-performance.blogspot.com
Best Practices
 $connection =
   new_db_connection("customer://1234");
 $statement =
      $connection->prepare(
           $sql_statement,
           $params
      );
 $result =
      $statement->execute();




69
         http://top-performance.blogspot.com
The VP R&D Open Seminar




BACKUP AND RESTORE


   http://top-performance.blogspot.com
Options
mysqldump
Physical disk copy
3rd Party solution: XtraDB, amanda




       http://top-performance.blogspot.com
Backup Your Server




http://top-performance.blogspot.com
The VP R&D Open Seminar




HANDLING PROBLEMS


   http://top-performance.blogspot.com
Error Log
   Get the Location:
[/]$ sudo more /etc/my.cnf | grep -i error
log-error=/var/lib/mysql/log.err
   Look for issues
[/]$ sudo tail -n 20 /var/lib/mysql/log.err
121025 13:24:23 InnoDB: Initializing buffer pool, size = 128.0M
121025 13:24:23 InnoDB: Completed initialization of buffer pool
121025 13:24:24 InnoDB: highest supported file format is
  Barracuda.
121025 13:24:25 InnoDB: Waiting for the background threads to
  start



            http://top-performance.blogspot.com
The VP R&D Open Seminar




DEVOPS MYSQL


   http://top-performance.blogspot.com
-e
mysql
-uuser
-ppassword
-Ddatabase
-hserver
-e”SELECT * FROM table;”




      http://top-performance.blogspot.com
Import Data
mysql
-uuser
-ppassword
-Ddatabase
-hserver
< /dir/to/filename.sql




       http://top-performance.blogspot.com
Export Data
mysqldump
-uuser
-ppassword
--databases database_name
--single-transaction --master-data=1 >
/path/to/backup/file.sql




       http://top-performance.blogspot.com
The VP R&D Open Seminar




MYSQL TUNING


   http://top-performance.blogspot.com
my.cnf




http://top-performance.blogspot.com
mysqltuner




http://top-performance.blogspot.com
Slow Query
log-slow-queries = /var/log/mysql/mysql-
slow.log
long_query_time = 1
log-queries-not-using-indexes




       http://top-performance.blogspot.com
explain
mysql> explain SELECT COUNT(*), post_type FROM wp_posts GROUP
BY post_type;
+--+-------------+--------+-----+-------------+-----------+-------+----+----+-----------+
|id| select_type |table   | type|possible_keys|key        |key_len|ref |rows| Extra
+--+-------------+--------+-----+-------------+-----------+-------+----+----+-----------+
|1 | SIMPLE      |wp_posts|index|NULL         |type_status| 140   |NULL|693 | Using index
+--+-------------+--------+-----+-------------+-----------+-------+----+----+-----------+
1 row in set (0.02 sec)




                 http://top-performance.blogspot.com
Profiling
http://top-
performance.blogspot.co.il/2011/07/mysql-
statement-profiling.html




      http://top-performance.blogspot.com
RAM Usage Optimization
     Preferred: SizeOf(database) < SizeOf(RAM)
     innodb_buffer_pool_size
       50-70% of your RAM




85
           http://top-performance.blogspot.com
Do We Utilize the Cache?
     SHOW STATUS LIKE 'Qcache%';

 Qcache_free_blocks        718
 Qcache_free_memory        13004008
 Qcache_hits               780759
 Qcache_inserts            56292
 Qcache_lowmem_prunes      0
 Qcache_not_cached         3711
 Qcache_queries_in_cache   1715
 Qcache_total_blocks       4344


86
           http://top-performance.blogspot.com
Cache Queries
     query_cache_type = 1
     query_cache_limit = 1M
     query_cache_size = 16M




87
           http://top-performance.blogspot.com
Buffer Optimization
     key_reads/key_read_requests < 0.01
     If not
       Increase Key Buffer




88
            http://top-performance.blogspot.com
CPU Optimization
     thread_concurrency = 2 X #(CPU Cores)




89
           http://top-performance.blogspot.com
Tune Your Server




http://top-performance.blogspot.com
Summary




http://top-performance.blogspot.com
What happens when mysql fails to start…
Create my.cnf
   touch /etc/my.cnf
Create the error log
   vi /etc/my.cnf
   [mysqld]
   log-error=/var/lib/mysql/log.err
If the my.cnf is already configured
   more /etc/my.cnf | grep –i error
Restart mysql
Find the error
   tail –n 50 /var/lib/mysql/log.err
In this case we kill all the mysql proceses
   ps –aux | grep –i mysql
   sudo kill process_id



           http://top-performance.blogspot.com
The Bottom Line: Grow ∞



 Thank you!
 and Keep Performing!

     Moshe Kaplan




93
          http://top-performance.blogspot.com

Más contenido relacionado

La actualidad más candente

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
Andreas Koop
 

La actualidad más candente (20)

Creating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and reactCreating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and react
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLI
 
Martin Aspeli Extending And Customising Plone 3
Martin Aspeli   Extending And Customising Plone 3Martin Aspeli   Extending And Customising Plone 3
Martin Aspeli Extending And Customising Plone 3
 
BaláZs Ree Introduction To Kss, Kinetic Style Sheets
BaláZs Ree   Introduction To Kss, Kinetic Style SheetsBaláZs Ree   Introduction To Kss, Kinetic Style Sheets
BaláZs Ree Introduction To Kss, Kinetic Style Sheets
 
webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
BPMS1
BPMS1BPMS1
BPMS1
 
Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回
 
Browser Caching and You: A Love Story
Browser Caching and You: A Love StoryBrowser Caching and You: A Love Story
Browser Caching and You: A Love Story
 
Enterprise Hosting
Enterprise HostingEnterprise Hosting
Enterprise Hosting
 
WPDay Bologna 2013
WPDay Bologna 2013WPDay Bologna 2013
WPDay Bologna 2013
 
Godefroid Chapelle Ajax With Plone 3 Kss Development Patterns
Godefroid Chapelle   Ajax With Plone 3   Kss Development PatternsGodefroid Chapelle   Ajax With Plone 3   Kss Development Patterns
Godefroid Chapelle Ajax With Plone 3 Kss Development Patterns
 
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
 
CakePHP - Admin Acl Controlled
CakePHP - Admin Acl ControlledCakePHP - Admin Acl Controlled
CakePHP - Admin Acl Controlled
 
Spring Booted, But... @JCConf 16', Taiwan
Spring Booted, But... @JCConf 16', TaiwanSpring Booted, But... @JCConf 16', Taiwan
Spring Booted, But... @JCConf 16', Taiwan
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 

Destacado

El silencio de san mamés
El silencio de san mamésEl silencio de san mamés
El silencio de san mamés
Lola Arroyo
 
El penalti en dos tiempos de samuel lamarca
El penalti en dos tiempos de samuel lamarcaEl penalti en dos tiempos de samuel lamarca
El penalti en dos tiempos de samuel lamarca
Lola Arroyo
 
IVANAREYNA_PORTFOLIO
IVANAREYNA_PORTFOLIOIVANAREYNA_PORTFOLIO
IVANAREYNA_PORTFOLIO
Ivana Reyna
 
Articulo javier programaciones
Articulo javier programacionesArticulo javier programaciones
Articulo javier programaciones
NataliaNPC
 

Destacado (13)

Simplyway
Simplyway Simplyway
Simplyway
 
Progetto BE@CTIVE
Progetto BE@CTIVEProgetto BE@CTIVE
Progetto BE@CTIVE
 
El silencio de san mamés
El silencio de san mamésEl silencio de san mamés
El silencio de san mamés
 
18
1818
18
 
[Russian 9 02_16] cook&talk_idea
[Russian 9 02_16] cook&talk_idea[Russian 9 02_16] cook&talk_idea
[Russian 9 02_16] cook&talk_idea
 
- العلاقات - رأس برأس
 - العلاقات - رأس برأس - العلاقات - رأس برأس
- العلاقات - رأس برأس
 
El penalti en dos tiempos de samuel lamarca
El penalti en dos tiempos de samuel lamarcaEl penalti en dos tiempos de samuel lamarca
El penalti en dos tiempos de samuel lamarca
 
Photo contest 2011 communication campain
Photo contest 2011 communication campainPhoto contest 2011 communication campain
Photo contest 2011 communication campain
 
IVANAREYNA_PORTFOLIO
IVANAREYNA_PORTFOLIOIVANAREYNA_PORTFOLIO
IVANAREYNA_PORTFOLIO
 
As consequências da ascensão de donald trump ao poder nos estados unidos
As consequências da ascensão de donald trump ao poder nos estados unidosAs consequências da ascensão de donald trump ao poder nos estados unidos
As consequências da ascensão de donald trump ao poder nos estados unidos
 
La jaula de los campos de sport
La jaula de los campos de sportLa jaula de los campos de sport
La jaula de los campos de sport
 
Articulo javier programaciones
Articulo javier programacionesArticulo javier programaciones
Articulo javier programaciones
 
Pascua judia y cristiana
Pascua judia y cristianaPascua judia y cristiana
Pascua judia y cristiana
 

Similar a MySQL crash course by moshe kaplan

Web systems architecture, Performance and More
Web systems architecture, Performance and MoreWeb systems architecture, Performance and More
Web systems architecture, Performance and More
Moshe Kaplan
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Masashi Shibata
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
KMS Technology
 
MySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD Tour
Ronald Bradford
 

Similar a MySQL crash course by moshe kaplan (20)

Web Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe KaplanWeb Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe Kaplan
 
Web systems architecture, Performance and More
Web systems architecture, Performance and MoreWeb systems architecture, Performance and More
Web systems architecture, Performance and More
 
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuffBig Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Testing Like a Pro - Chef Infrastructure Testing
Testing Like a Pro - Chef Infrastructure TestingTesting Like a Pro - Chef Infrastructure Testing
Testing Like a Pro - Chef Infrastructure Testing
 
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...
 
Stored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiStored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayi
 
Brief introduction into SQL injection attack scenarios
Brief introduction into SQL injection attack scenariosBrief introduction into SQL injection attack scenarios
Brief introduction into SQL injection attack scenarios
 
How to Contribute Code to MySQL?
How to Contribute Code to MySQL?How to Contribute Code to MySQL?
How to Contribute Code to MySQL?
 
Webinar - Setup MySQL with Puppet
Webinar - Setup MySQL with PuppetWebinar - Setup MySQL with Puppet
Webinar - Setup MySQL with Puppet
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
 
Raj mysql
Raj mysqlRaj mysql
Raj mysql
 
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
 
2017 OWASP SanFran March Meetup - Hacking SQL Server on Scale with PowerShell
2017 OWASP SanFran March Meetup - Hacking SQL Server on Scale with PowerShell2017 OWASP SanFran March Meetup - Hacking SQL Server on Scale with PowerShell
2017 OWASP SanFran March Meetup - Hacking SQL Server on Scale with PowerShell
 
SQLMAP Tool Usage - A Heads Up
SQLMAP Tool Usage - A  Heads UpSQLMAP Tool Usage - A  Heads Up
SQLMAP Tool Usage - A Heads Up
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
 
MySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD Tour
 
MySQL 8.0.19 - New Features Summary
MySQL 8.0.19 - New Features SummaryMySQL 8.0.19 - New Features Summary
MySQL 8.0.19 - New Features Summary
 
10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...
 
Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)
 

Más de Moshe Kaplan

mongoDB Performance
mongoDB PerformancemongoDB Performance
mongoDB Performance
Moshe Kaplan
 

Más de Moshe Kaplan (20)

Spark and C Integration
Spark and C IntegrationSpark and C Integration
Spark and C Integration
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
 
Introduciton to Python
Introduciton to PythonIntroduciton to Python
Introduciton to Python
 
Creating Big Data: Methodology
Creating Big Data: MethodologyCreating Big Data: Methodology
Creating Big Data: Methodology
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
Redis training for java software engineers
Redis training for java software engineersRedis training for java software engineers
Redis training for java software engineers
 
MongoDB training for java software engineers
MongoDB training for java software engineersMongoDB training for java software engineers
MongoDB training for java software engineers
 
MongoDB from Basics to Scale
MongoDB from Basics to ScaleMongoDB from Basics to Scale
MongoDB from Basics to Scale
 
MongoDB Best Practices for Developers
MongoDB Best Practices for DevelopersMongoDB Best Practices for Developers
MongoDB Best Practices for Developers
 
The api economy
The api economyThe api economy
The api economy
 
Scale and Cloud Design Patterns
Scale and Cloud Design PatternsScale and Cloud Design Patterns
Scale and Cloud Design Patterns
 
Do Big Data and NoSQL Fit Your Needs?
Do Big Data and NoSQL Fit Your Needs?Do Big Data and NoSQL Fit Your Needs?
Do Big Data and NoSQL Fit Your Needs?
 
The VP R&D Open Seminar on Project Management, SCRUM, Agile and Continuous De...
The VP R&D Open Seminar on Project Management, SCRUM, Agile and Continuous De...The VP R&D Open Seminar on Project Management, SCRUM, Agile and Continuous De...
The VP R&D Open Seminar on Project Management, SCRUM, Agile and Continuous De...
 
MySQL Multi Master Replication
MySQL Multi Master ReplicationMySQL Multi Master Replication
MySQL Multi Master Replication
 
mongoDB Performance
mongoDB PerformancemongoDB Performance
mongoDB Performance
 
VP R&D Open Seminar: Caching
VP R&D Open Seminar: CachingVP R&D Open Seminar: Caching
VP R&D Open Seminar: Caching
 
Expert Days: The VP R&D Open Seminar: Project Management
Expert Days: The VP R&D Open Seminar: Project ManagementExpert Days: The VP R&D Open Seminar: Project Management
Expert Days: The VP R&D Open Seminar: Project Management
 
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
 
Database2011 MySQL Sharding
Database2011 MySQL ShardingDatabase2011 MySQL Sharding
Database2011 MySQL Sharding
 
Cloud Computing Design Best Practices
Cloud Computing Design Best PracticesCloud Computing Design Best Practices
Cloud Computing Design Best Practices
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

MySQL crash course by moshe kaplan

  • 1. The VP R&D Open Seminar MySQL Crash Course From basics to experts mokplan@gmail.com http://top-performance.blogspot.com
  • 2. The VP R&D Open Seminar WHY WE CHOSE MYSQL? http://top-performance.blogspot.com
  • 3. Who is Using MySQL? 3 http://top-performance.blogspot.com
  • 4. Who is Behind MySQL http://top-performance.blogspot.com
  • 5. What MySQL is Made of? 5 http://top-performance.blogspot.com http://dev.mysql.com/tech-resources/articles/mysql_5.0_psea1.html
  • 6. MySQL Limitations 50-150M Records/Table 50-5000 SELECT Statements/Second 6 http://top-performance.blogspot.com
  • 7. Why Do I Care? From 0 to 100 (US mass adaptation) Phone: 100 yrs Radio: 40 yrs TV: 30 yrs Mobile: 20 yrs Internet: 10 yrs Facebook: 2 yrs 7 http://top-performance.blogspot.com
  • 8. 100K New Users/Week 8 http://top-performance.blogspot.com
  • 9. The VP R&D Open Seminar WHAT MYSQL IS MADE OF? http://top-performance.blogspot.com
  • 10. MySQL Structure Daemon /var/lib/mysql ibdata1 ib_logfile0, Ib_logfile1 /mysql /database /performance_schema /etc/my.cnf http://top-performance.blogspot.com
  • 11. What to Install wget mysql_package yum –y localinstall mysql_package The Packages: Devel+Client+Server Relevant platform (x86/x64) Relevant operating system http://top-performance.blogspot.com
  • 13. The VP R&D Open Seminar DATABASE LOGICAL DESIGN (OR ERD) http://top-performance.blogspot.com
  • 14. Instances, Schemas and inside information http://top-performance.blogspot.com
  • 15. 1:Many schoolId: schoolId: Primary Key Foreign Key http://top-performance.blogspot.com
  • 16. Many:Many ?: ?: Primary Key Foreign Key http://top-performance.blogspot.com
  • 17. Many:Many in Practice testId: testId, studentId: Primary Key studentId: Primary Key Foreign Key http://top-performance.blogspot.com
  • 18. Design a Student Information System ERD http://top-performance.blogspot.com
  • 19. The VP R&D Open Seminar FROM ERD TO A DATABASE http://top-performance.blogspot.com
  • 20. Connect to the Database http://top-performance.blogspot.com
  • 23. Implement the a Student Information System ERD http://top-performance.blogspot.com
  • 24. The VP R&D Open Seminar SQL: DDL http://top-performance.blogspot.com
  • 25. Databases Manipulation SHOW DATABASES; CREATE DATABASE mydb; DROP DATABASE mydb; USE mydb; http://top-performance.blogspot.com
  • 26. Tables Manipulation SHOW TABLES; CREATE TABLE users ( id int, INDEX users_id (id) ); DROP TABLE users; ALTER TABLE users ADD INDEX IX_id (id); ALTER TABLE users DROP INDEX IX_id; http://top-performance.blogspot.com
  • 27. The VP R&D Open Seminar SQL: DML http://top-performance.blogspot.com
  • 28. SELECT SELECT table.field, table.* FROM table WHERE table.field = 123 ORDER BY field1, field2 DESC http://top-performance.blogspot.com
  • 29. SELECT + Join SELECT c.*, u.* FROM classes c INNER JOIN users u ON c.teacherId = u.id http://top-performance.blogspot.com
  • 31. GROUP BY SELECT gender, count(id) FROM users WHERE gender = ‘M’ GROUP BY gender HAVING count(id) > 10 http://top-performance.blogspot.com
  • 32. UNION SELECT id FROM users WHERE gender = ‘M’ UNION ALL SELECT id FROM users WHERE gender = ‘F’ ORDER BY id; http://top-performance.blogspot.com
  • 33. UPDATE UPDATE users SET gender = ‘M’ WHERE gender IS NULL; http://top-performance.blogspot.com
  • 34. INSERT INSERT INTO users (gender) VALUES (‘M’); INSERT INTO users (gender) SELECT gender FROM users WHERE gender = ‘M’; http://top-performance.blogspot.com
  • 35. DELETE DELETE FROM users WHERE gender = ‘M’; http://top-performance.blogspot.com
  • 36. The VP R&D Open Seminar MySQL Authentication and Authorization SECURITY http://top-performance.blogspot.com
  • 37. Root User First Time mysqladmin -u root password NEWPASSWORD Nth Time mysqladmin -u root -p'oldpassword' password newpass How to enter Mysql –uuser_name –ppassword –D database_name -h host_name/ip -A http://top-performance.blogspot.com
  • 38. Users Table mysql> SELECT * FROM mysql.user limit 1G *************************** 1. row *************************** Host: localhost User: root Password: *4FB5C598BC3FF56E262F863A715F8CB2976A9C69 Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y …. 1 row in set (0.00 sec) http://top-performance.blogspot.com
  • 39. Create a Users and Provide Permissions -- Create a user w/ password CREATE USER 'readonly'@'%' IDENTIFIED BY ‘sakexkas'; -- Grant Permissions GRANT select ON my_db.* to 'readonly'@'%'; GRANT ALL PRIVILEGES ON *.* to ‘master_user’@’%’ WITH GRANT OPTION; FLUSH PRIVILEGES; -- Beware of too complex passwords http://top-performance.blogspot.com
  • 40. The VP R&D Open Seminar MYSQL AND LINUX ISSUES http://top-performance.blogspot.com
  • 41. Built in Linux Security Measures IP TABLES sudo /etc/init.d/iptables stop sudo yum –y remove iptables Configure the relevant rules SELinux sudo echo 0 > /selinux/enforce vi /etc/selinux/config: SELINUX=enforcing  SELINUX=disabled Files Limit (Table Partitioning) /etc/security/limits.conf mysql soft nofile 8192 mysql hard nofile 8192 my.cnf: open_files_limit = 8192 http://top-performance.blogspot.com
  • 43. Create a Master/Slave configuration http://top-performance.blogspot.com
  • 44. The VP R&D Open Seminar HIGH AVAILABILITY ARCHITECTURES http://top-performance.blogspot.com
  • 46. Master/Master ? http://top-performance.blogspot.com
  • 47. Show Status (1) mysql> show slave statusG *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.12.12.167 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master.000094 Read_Master_Log_Pos: 167250867 Relay_Log_File: mysqld-relay-bin.000137 Relay_Log_Pos: 167251010 Relay_Master_Log_File: master.000094 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: mysql.%,information_schema.% http://top-performance.blogspot.com
  • 48. Show Status (2) Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 167250867 Relay_Log_Space: 167251310 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.02 sec) http://top-performance.blogspot.com
  • 49. Skip DON’T DO THAT unless you have to! The Process: STOP SLAVE; SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; START SLAVE; SHOW SLAVE STATUSG http://top-performance.blogspot.com
  • 50. How to Implement? Stop a Master and record position Copy a Master (instance/disk) to a Slave Start the Master Change slave server-id SET MASTER HOST … START SLAVE Verify Or… http://top-performance.blogspot.co.il/2012/03/how-to- setup-mysql-replication-in-11.html http://top-performance.blogspot.com
  • 51. Create a Master/Slave configuration http://top-performance.blogspot.com
  • 52. The VP R&D Open Seminar SCALE-ABLE ARCHITECTURES http://top-performance.blogspot.com
  • 53. Do You Remember? 53 http://top-performance.blogspot.com
  • 54. Strategy A: Sharding 54 http://top-performance.blogspot.com
  • 55. Strategy B: In Memory Databases 55 http://top-performance.blogspot.com
  • 56. 700 Inserts/Sec In Memory Engine 3000 Inserts/Sec Amazon AWS Standard InnoDB Engine Large Instance 700 Inserts/Sec 56 http://top-performance.blogspot.com
  • 57. IMDB - Implementation 57 http://top-performance.blogspot.com
  • 58. Lessons Cache: MySQL IMDB HA: MySQL Replication Persistence: Periodic 5min Batch Scalability: Sharding 4 Bill Req/Day using 25 machines (2000/s) 58 http://top-performance.blogspot.com
  • 59. Strategy C: MapReduce 59 http://top-performance.blogspot.com
  • 60. Strategy D: NoSQL insert get multiget remove truncate <Key, Value> http://wiki.apache.org/cassandra/API 60 http://top-performance.blogspot.com
  • 61. When Should I Choose NoSQL? Eventually Consistent Document Store Key Value http://guyharrison.squarespace.com/blog/tag/nosql 61 http://top-performance.blogspot.com
  • 62. Sharding Again 62 http://top-performance.blogspot.com
  • 63. Vertical Sharding 63 http://top-performance.blogspot.com
  • 64. Horizontal Sharding Static Hashing Complex growth Mod 10 = 0 Mod 10 = 1 Simple Mod 10 = 2 Mod 10 = 3 Mod 10 = 4 Mod 10 = 5 Mod 10 = 6 Mod 10 = 7 Mod 10 = 8 Mod 10 = 9 64 http://top-performance.blogspot.com
  • 65. Horizontal Sharding Key locations are defined in a directory Simple growth Directory is SPOF 65 http://top-performance.blogspot.com
  • 66. Horizontal Sharding Static Hashing with Directory Mapping Simple Growth Small Directory still SPOF Mod 1000 = 4 66 http://top-performance.blogspot.com
  • 67. Horizontal Sharding Each key signed by DB# generated on creation Simple growth New key generation is SPOF 67 http://top-performance.blogspot.com
  • 68. Limitations: Reporting 68 http://top-performance.blogspot.com
  • 69. Best Practices $connection = new_db_connection("customer://1234"); $statement = $connection->prepare( $sql_statement, $params ); $result = $statement->execute(); 69 http://top-performance.blogspot.com
  • 70. The VP R&D Open Seminar BACKUP AND RESTORE http://top-performance.blogspot.com
  • 71. Options mysqldump Physical disk copy 3rd Party solution: XtraDB, amanda http://top-performance.blogspot.com
  • 73. The VP R&D Open Seminar HANDLING PROBLEMS http://top-performance.blogspot.com
  • 74. Error Log Get the Location: [/]$ sudo more /etc/my.cnf | grep -i error log-error=/var/lib/mysql/log.err Look for issues [/]$ sudo tail -n 20 /var/lib/mysql/log.err 121025 13:24:23 InnoDB: Initializing buffer pool, size = 128.0M 121025 13:24:23 InnoDB: Completed initialization of buffer pool 121025 13:24:24 InnoDB: highest supported file format is Barracuda. 121025 13:24:25 InnoDB: Waiting for the background threads to start http://top-performance.blogspot.com
  • 75. The VP R&D Open Seminar DEVOPS MYSQL http://top-performance.blogspot.com
  • 76. -e mysql -uuser -ppassword -Ddatabase -hserver -e”SELECT * FROM table;” http://top-performance.blogspot.com
  • 78. Export Data mysqldump -uuser -ppassword --databases database_name --single-transaction --master-data=1 > /path/to/backup/file.sql http://top-performance.blogspot.com
  • 79. The VP R&D Open Seminar MYSQL TUNING http://top-performance.blogspot.com
  • 82. Slow Query log-slow-queries = /var/log/mysql/mysql- slow.log long_query_time = 1 log-queries-not-using-indexes http://top-performance.blogspot.com
  • 83. explain mysql> explain SELECT COUNT(*), post_type FROM wp_posts GROUP BY post_type; +--+-------------+--------+-----+-------------+-----------+-------+----+----+-----------+ |id| select_type |table | type|possible_keys|key |key_len|ref |rows| Extra +--+-------------+--------+-----+-------------+-----------+-------+----+----+-----------+ |1 | SIMPLE |wp_posts|index|NULL |type_status| 140 |NULL|693 | Using index +--+-------------+--------+-----+-------------+-----------+-------+----+----+-----------+ 1 row in set (0.02 sec) http://top-performance.blogspot.com
  • 85. RAM Usage Optimization Preferred: SizeOf(database) < SizeOf(RAM) innodb_buffer_pool_size 50-70% of your RAM 85 http://top-performance.blogspot.com
  • 86. Do We Utilize the Cache? SHOW STATUS LIKE 'Qcache%'; Qcache_free_blocks 718 Qcache_free_memory 13004008 Qcache_hits 780759 Qcache_inserts 56292 Qcache_lowmem_prunes 0 Qcache_not_cached 3711 Qcache_queries_in_cache 1715 Qcache_total_blocks 4344 86 http://top-performance.blogspot.com
  • 87. Cache Queries query_cache_type = 1 query_cache_limit = 1M query_cache_size = 16M 87 http://top-performance.blogspot.com
  • 88. Buffer Optimization key_reads/key_read_requests < 0.01 If not Increase Key Buffer 88 http://top-performance.blogspot.com
  • 89. CPU Optimization thread_concurrency = 2 X #(CPU Cores) 89 http://top-performance.blogspot.com
  • 92. What happens when mysql fails to start… Create my.cnf touch /etc/my.cnf Create the error log vi /etc/my.cnf [mysqld] log-error=/var/lib/mysql/log.err If the my.cnf is already configured more /etc/my.cnf | grep –i error Restart mysql Find the error tail –n 50 /var/lib/mysql/log.err In this case we kill all the mysql proceses ps –aux | grep –i mysql sudo kill process_id http://top-performance.blogspot.com
  • 93. The Bottom Line: Grow ∞ Thank you! and Keep Performing! Moshe Kaplan 93 http://top-performance.blogspot.com

Notas del editor

  1. The Matrix, The Architect Speach http://www.youtube.com/watch?v=mod6xr-lyBc A better w/ titles: http://www.youtube.com/watch?v=K3OXs_5AD2A Second, Kong foo: http://www.youtube.com/watch?v=j82GKTgVDkw Twitter Source: http://www.slideshare.net/Blaine/scaling-twitter
  2. The world is changing more and more fast You have to minimize NRE You must support unexpected demand You must provide top service (people now leaves cell operator after single incident, rather then 5, 10 years ago Firms a vulnerable – Citi worth 20Bill $ instead of 200 Bill a year ago Break and Mortar bookstores 15 years ago and Amazon…. Will it happen again to banks, insurance, real estate agencies… IS YOUR MARKET THE NEXT FOR PENETRATION – Finance? Real Estate?How to win a rival that is not existing yet? http://www.johnmwillis.com/ibm/cloud-computing-and-the-enterprise/ -
  3. Sharded database – OLTP Little/No reporting OLAP – must be implemented for reporting Loads data from sharded DBs Custom mechanism Any commercial
  4. http://www.prelovac.com/vladimir/wordpress-optimization-guide
  5. Start with nothing: storage, FW, LB, Server and grow… Can buy servers for more than hour