SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
MySQL Essentials
                            2012

          Chris Henry
          @chrishnry




Sunday, January 20, 13
hello.




Sunday, January 20, 13
MySQL @ Behance


       Powers Be.net
       17 Dell R710s
       120GB
       XFS Filesystem

       Percona 5.5




Sunday, January 20, 13
What Version of MySQL?


       - Does it actually matter? Fuck yes.

      mysql> SELECT VERSION()
      Welcome to the MySQL monitor.
      Your MySQL connection id is 54248515
      Server version: 5.5.24-55-log Percona Server (GPL),
      Release rel26.0, Revision 256




Sunday, January 20, 13
Percona

        • Why?
        http://www.percona.com/

        • Percona Toolkit
        http://www.percona.com/software/percona-
        toolkit




Sunday, January 20, 13
MySQL Engines


        • Pluggable architecture.
        • INNODB vs MyISAM
           • Transactions
           • Locking
           • Fulltext
        • Should be InnoDB for most things

        http://dev.mysql.com/doc/refman/5.5/en/
        storage-engines.html
Sunday, January 20, 13
Configuration




        • table_open_cache
        • innodb_buffer_pool
        • max_connections
        • key_buffer_size




Sunday, January 20, 13
Slow Log


        my.cnf
        slow-query-log-file = /var/lib/mysqllogs/slow-log
        long-query-time     = 2




Sunday, January 20, 13
Tuning - Easy Wins


        • skip-name-resolve
        • Linux Swappiness




Sunday, January 20, 13
Slow Log Output


        # Query_time: 0.015029 Lock_time: 0.000044 Rows_sent: 481
        Rows_examined: 5080 Rows_affected: 0 Rows_read: 481
        # Bytes_sent: 4888 Tmp_tables: 1 Tmp_disk_tables: 0
        Tmp_table_sizes: 126992
        # Filesort: Yes Filesort_on_disk: No Merge_passes: 0
        #   InnoDB_IO_r_ops: 0 InnoDB_IO_r_bytes: 0
        InnoDB_IO_r_wait: 0.000000
        #   InnoDB_rec_lock_wait: 0.000000 InnoDB_queue_wait:
        0.000000
        SELECT DISTINCT proj.id
          FROM projects proj
             INNER JOIN project_summary ps ON proj.id=ps.proj_id
          WHERE proj.published = 1 AND proj.privacy2 = 1
          ORDER BY ps.apps DESC
          LIMIT 0, 481;




Sunday, January 20, 13
EXPLAIN Output
 *************************** 1. row ***************************
            id: 1
   select_type: SIMPLE
         table: proj
          type: ref
 possible_keys: PRIMARY,published,privacy2,
           key: privacy2
       key_len: 2
           ref: const,const
          rows: 1
      filtered: 100.00
         Extra: Using index; Using temporary; Using filesort
 *************************** 2. row ***************************
            id: 1
   select_type: SIMPLE
         table: ps
          type: ref
 possible_keys: proj_id
           key: proj_id
       key_len: 4
           ref: be_net2.proj.id
          rows: 1
      filtered: 100.00
         Extra: Distinct
 2 rows in set, 1 warning (0.00 sec)


Sunday, January 20, 13
Table Design


        • Data Types
        • Relations
        • Normal Form




Sunday, January 20, 13
Data Types


        • Right tool for the job
        • Numeric
        • String
        • Temporal
        • Spatial

Sunday, January 20, 13
Integer Data Types


        • How big?
        • Signed or unsigned?
        • What the hell does that number in parens
        mean?

        • Integer types are great for storing things like
        type attributes.

Sunday, January 20, 13
Integer Table


        CREATE TABLE IF NOT EXISTS `integers` (
          `tiny` tinyint(4) NOT NULL,
          `tiny_zerofill` tinyint(10) unsigned zerofill NOT NULL,
          `small` smallint(6) NOT NULL,
          `medium` mediumint(9) NOT NULL,
          `int` int(11) NOT NULL,
          `int_unsigned` int(10) unsigned NOT NULL,
          `big` bigint(20) NOT NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;




Sunday, January 20, 13
Decimals


        • Fixed Point
        • DECIMAL (5,2)




Sunday, January 20, 13
Text Datatypes


        • CHAR (0 to 255)
        • VARCHAR (0 to 65,535) + length




Sunday, January 20, 13
Bigger Text Datatypes


        • TINYTEXT
        • TEXT
        • MEDIUMTEXT
        • LONGTEXT
        http://dev.mysql.com/doc/refman/5.5/en/string-type-overview.html




Sunday, January 20, 13
Character Sets + Collation


        • A Character Set is a set of symbols and
        encodings.

        • Collation is the set of rules for comparing
        characters.

        • utf8 / utf8_unicode_ci is best bet for most
        Western languages.



Sunday, January 20, 13
Temporal


        • DATE
        • TIME
        • DATETIME
        • TIMESTAMP
        http://dev.mysql.com/doc/refman/5.5/en/date-and-time-types.html




Sunday, January 20, 13
Table Design


        • Primary Key
        • Compound Keys
        • Indexes
        http://dev.mysql.com/doc/refman/5.5/en/date-and-time-types.html




Sunday, January 20, 13
Querying


        • Sakila Database
        • DVD Rental Store
        http://dev.mysql.com/doc/sakila/en/index.html




Sunday, January 20, 13
That’s it!


      Thank you all for coming!

      Feedback is welcome!




Sunday, January 20, 13

Weitere ähnliche Inhalte

Was ist angesagt?

10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators  10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators iammutex
 
Redis/Lessons learned
Redis/Lessons learnedRedis/Lessons learned
Redis/Lessons learnedTit Petric
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisKnoldus Inc.
 
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...ronwarshawsky
 
A simple introduction to redis
A simple introduction to redisA simple introduction to redis
A simple introduction to redisZhichao Liang
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica setsRandall Hunt
 
Building Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBBuilding Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBAshnikbiz
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHPfwso
 
MongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and MonitoringMongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and MonitoringMongoDB
 
Developing and Deploying Apps with the Postgres FDW
Developing and Deploying Apps with the Postgres FDWDeveloping and Deploying Apps with the Postgres FDW
Developing and Deploying Apps with the Postgres FDWJonathan Katz
 
Installing postgres & postgis
Installing postgres & postgisInstalling postgres & postgis
Installing postgres & postgisJohn Ashmead
 
Ceph Day KL - Bluestore
Ceph Day KL - Bluestore Ceph Day KL - Bluestore
Ceph Day KL - Bluestore Ceph Community
 
Postgresql search demystified
Postgresql search demystifiedPostgresql search demystified
Postgresql search demystifiedjavier ramirez
 
Storage Methods for Nonstandard Data Patterns
Storage Methods for Nonstandard Data PatternsStorage Methods for Nonstandard Data Patterns
Storage Methods for Nonstandard Data PatternsBob Burgess
 

Was ist angesagt? (20)

Indexing
IndexingIndexing
Indexing
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
 
10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators  10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators
 
Redis basics
Redis basicsRedis basics
Redis basics
 
Redis/Lessons learned
Redis/Lessons learnedRedis/Lessons learned
Redis/Lessons learned
 
MongoDB & PHP
MongoDB & PHPMongoDB & PHP
MongoDB & PHP
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
A simple introduction to redis
A simple introduction to redisA simple introduction to redis
A simple introduction to redis
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica sets
 
Building Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBBuilding Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDB
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHP
 
MongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and MonitoringMongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and Monitoring
 
Developing and Deploying Apps with the Postgres FDW
Developing and Deploying Apps with the Postgres FDWDeveloping and Deploying Apps with the Postgres FDW
Developing and Deploying Apps with the Postgres FDW
 
Installing postgres & postgis
Installing postgres & postgisInstalling postgres & postgis
Installing postgres & postgis
 
Ceph Day KL - Bluestore
Ceph Day KL - Bluestore Ceph Day KL - Bluestore
Ceph Day KL - Bluestore
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
 
Postgresql search demystified
Postgresql search demystifiedPostgresql search demystified
Postgresql search demystified
 
Storage Methods for Nonstandard Data Patterns
Storage Methods for Nonstandard Data PatternsStorage Methods for Nonstandard Data Patterns
Storage Methods for Nonstandard Data Patterns
 

Ähnlich wie Mysql

Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersJonathan Levin
 
Big Data with MySQL
Big Data with MySQLBig Data with MySQL
Big Data with MySQLIvan Zoratti
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015Dave Stokes
 
String Comparison Surprises: Did Postgres lose my data?
String Comparison Surprises: Did Postgres lose my data?String Comparison Surprises: Did Postgres lose my data?
String Comparison Surprises: Did Postgres lose my data?Jeremy Schneider
 
Star schema my sql
Star schema   my sqlStar schema   my sql
Star schema my sqldeathsubte
 
扩展世界上最大的图片Blog社区
扩展世界上最大的图片Blog社区扩展世界上最大的图片Blog社区
扩展世界上最大的图片Blog社区yiditushe
 
Fotolog: Scaling the World's Largest Photo Blogging Community
Fotolog: Scaling the World's Largest Photo Blogging CommunityFotolog: Scaling the World's Largest Photo Blogging Community
Fotolog: Scaling the World's Largest Photo Blogging Communityfarhan "Frank"​ mashraqi
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practiceswebhostingguy
 
Sql on hadoop the secret presentation.3pptx
Sql on hadoop  the secret presentation.3pptxSql on hadoop  the secret presentation.3pptx
Sql on hadoop the secret presentation.3pptxPaulo Alonso
 
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...Wes McKinney
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best PracticesDavid Keener
 
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...Insight Technology, Inc.
 
Fosdem managing my sql with percona toolkit
Fosdem managing my sql with percona toolkitFosdem managing my sql with percona toolkit
Fosdem managing my sql with percona toolkitFrederic Descamps
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
M|18 Understanding the Architecture of MariaDB ColumnStore
M|18 Understanding the Architecture of MariaDB ColumnStoreM|18 Understanding the Architecture of MariaDB ColumnStore
M|18 Understanding the Architecture of MariaDB ColumnStoreMariaDB plc
 
Bogdan Kecman INIT Presentation
Bogdan Kecman INIT PresentationBogdan Kecman INIT Presentation
Bogdan Kecman INIT Presentationarhismece
 
MySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines SlidesMySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines SlidesSeveralnines
 

Ähnlich wie Mysql (20)

Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for Developers
 
Quick Wins
Quick WinsQuick Wins
Quick Wins
 
Big Data with MySQL
Big Data with MySQLBig Data with MySQL
Big Data with MySQL
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
String Comparison Surprises: Did Postgres lose my data?
String Comparison Surprises: Did Postgres lose my data?String Comparison Surprises: Did Postgres lose my data?
String Comparison Surprises: Did Postgres lose my data?
 
Star schema my sql
Star schema   my sqlStar schema   my sql
Star schema my sql
 
扩展世界上最大的图片Blog社区
扩展世界上最大的图片Blog社区扩展世界上最大的图片Blog社区
扩展世界上最大的图片Blog社区
 
Fotolog: Scaling the World's Largest Photo Blogging Community
Fotolog: Scaling the World's Largest Photo Blogging CommunityFotolog: Scaling the World's Largest Photo Blogging Community
Fotolog: Scaling the World's Largest Photo Blogging Community
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practices
 
Sql on hadoop the secret presentation.3pptx
Sql on hadoop  the secret presentation.3pptxSql on hadoop  the secret presentation.3pptx
Sql on hadoop the secret presentation.3pptx
 
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best Practices
 
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
 
Fosdem managing my sql with percona toolkit
Fosdem managing my sql with percona toolkitFosdem managing my sql with percona toolkit
Fosdem managing my sql with percona toolkit
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
M|18 Understanding the Architecture of MariaDB ColumnStore
M|18 Understanding the Architecture of MariaDB ColumnStoreM|18 Understanding the Architecture of MariaDB ColumnStore
M|18 Understanding the Architecture of MariaDB ColumnStore
 
Bogdan Kecman INIT Presentation
Bogdan Kecman INIT PresentationBogdan Kecman INIT Presentation
Bogdan Kecman INIT Presentation
 
MySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines SlidesMySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines Slides
 

Mysql

  • 1. MySQL Essentials 2012 Chris Henry @chrishnry Sunday, January 20, 13
  • 3. MySQL @ Behance Powers Be.net 17 Dell R710s 120GB XFS Filesystem Percona 5.5 Sunday, January 20, 13
  • 4. What Version of MySQL? - Does it actually matter? Fuck yes. mysql> SELECT VERSION() Welcome to the MySQL monitor. Your MySQL connection id is 54248515 Server version: 5.5.24-55-log Percona Server (GPL), Release rel26.0, Revision 256 Sunday, January 20, 13
  • 5. Percona • Why? http://www.percona.com/ • Percona Toolkit http://www.percona.com/software/percona- toolkit Sunday, January 20, 13
  • 6. MySQL Engines • Pluggable architecture. • INNODB vs MyISAM • Transactions • Locking • Fulltext • Should be InnoDB for most things http://dev.mysql.com/doc/refman/5.5/en/ storage-engines.html Sunday, January 20, 13
  • 7. Configuration • table_open_cache • innodb_buffer_pool • max_connections • key_buffer_size Sunday, January 20, 13
  • 8. Slow Log my.cnf slow-query-log-file = /var/lib/mysqllogs/slow-log long-query-time = 2 Sunday, January 20, 13
  • 9. Tuning - Easy Wins • skip-name-resolve • Linux Swappiness Sunday, January 20, 13
  • 10. Slow Log Output # Query_time: 0.015029 Lock_time: 0.000044 Rows_sent: 481 Rows_examined: 5080 Rows_affected: 0 Rows_read: 481 # Bytes_sent: 4888 Tmp_tables: 1 Tmp_disk_tables: 0 Tmp_table_sizes: 126992 # Filesort: Yes Filesort_on_disk: No Merge_passes: 0 # InnoDB_IO_r_ops: 0 InnoDB_IO_r_bytes: 0 InnoDB_IO_r_wait: 0.000000 # InnoDB_rec_lock_wait: 0.000000 InnoDB_queue_wait: 0.000000 SELECT DISTINCT proj.id FROM projects proj INNER JOIN project_summary ps ON proj.id=ps.proj_id WHERE proj.published = 1 AND proj.privacy2 = 1 ORDER BY ps.apps DESC LIMIT 0, 481; Sunday, January 20, 13
  • 11. EXPLAIN Output *************************** 1. row *************************** id: 1 select_type: SIMPLE table: proj type: ref possible_keys: PRIMARY,published,privacy2, key: privacy2 key_len: 2 ref: const,const rows: 1 filtered: 100.00 Extra: Using index; Using temporary; Using filesort *************************** 2. row *************************** id: 1 select_type: SIMPLE table: ps type: ref possible_keys: proj_id key: proj_id key_len: 4 ref: be_net2.proj.id rows: 1 filtered: 100.00 Extra: Distinct 2 rows in set, 1 warning (0.00 sec) Sunday, January 20, 13
  • 12. Table Design • Data Types • Relations • Normal Form Sunday, January 20, 13
  • 13. Data Types • Right tool for the job • Numeric • String • Temporal • Spatial Sunday, January 20, 13
  • 14. Integer Data Types • How big? • Signed or unsigned? • What the hell does that number in parens mean? • Integer types are great for storing things like type attributes. Sunday, January 20, 13
  • 15. Integer Table CREATE TABLE IF NOT EXISTS `integers` ( `tiny` tinyint(4) NOT NULL, `tiny_zerofill` tinyint(10) unsigned zerofill NOT NULL, `small` smallint(6) NOT NULL, `medium` mediumint(9) NOT NULL, `int` int(11) NOT NULL, `int_unsigned` int(10) unsigned NOT NULL, `big` bigint(20) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Sunday, January 20, 13
  • 16. Decimals • Fixed Point • DECIMAL (5,2) Sunday, January 20, 13
  • 17. Text Datatypes • CHAR (0 to 255) • VARCHAR (0 to 65,535) + length Sunday, January 20, 13
  • 18. Bigger Text Datatypes • TINYTEXT • TEXT • MEDIUMTEXT • LONGTEXT http://dev.mysql.com/doc/refman/5.5/en/string-type-overview.html Sunday, January 20, 13
  • 19. Character Sets + Collation • A Character Set is a set of symbols and encodings. • Collation is the set of rules for comparing characters. • utf8 / utf8_unicode_ci is best bet for most Western languages. Sunday, January 20, 13
  • 20. Temporal • DATE • TIME • DATETIME • TIMESTAMP http://dev.mysql.com/doc/refman/5.5/en/date-and-time-types.html Sunday, January 20, 13
  • 21. Table Design • Primary Key • Compound Keys • Indexes http://dev.mysql.com/doc/refman/5.5/en/date-and-time-types.html Sunday, January 20, 13
  • 22. Querying • Sakila Database • DVD Rental Store http://dev.mysql.com/doc/sakila/en/index.html Sunday, January 20, 13
  • 23. That’s it! Thank you all for coming! Feedback is welcome! Sunday, January 20, 13