MySQL Essentials                            2012          Chris Henry          @chrishnrySunday, January 20, 13
hello.Sunday, January 20, 13
MySQL @ Behance       Powers Be.net       17 Dell R710s       120GB       XFS Filesystem       Percona 5.5Sunday, January ...
What Version of MySQL?       - Does it actually matter? Fuck yes.      mysql> SELECT VERSION()      Welcome to the MySQL m...
Percona        • Why?        http://www.percona.com/        • Percona Toolkit        http://www.percona.com/software/perco...
MySQL Engines        • Pluggable architecture.        • INNODB vs MyISAM           • Transactions           • Locking     ...
Configuration        • table_open_cache        • innodb_buffer_pool        • max_connections        • key_buffer_sizeSunda...
Slow Log        my.cnf        slow-query-log-file = /var/lib/mysqllogs/slow-log        long-query-time     = 2Sunday, Janu...
Tuning - Easy Wins        • skip-name-resolve        • Linux SwappinessSunday, January 20, 13
Slow Log Output        # Query_time: 0.015029 Lock_time: 0.000044 Rows_sent: 481        Rows_examined: 5080 Rows_affected:...
EXPLAIN Output *************************** 1. row ***************************            id: 1   select_type: SIMPLE      ...
Table Design        • Data Types        • Relations        • Normal FormSunday, January 20, 13
Data Types        • Right tool for the job        • Numeric        • String        • Temporal        • SpatialSunday, Janu...
Integer Data Types        • How big?        • Signed or unsigned?        • What the hell does that number in parens       ...
Integer Table        CREATE TABLE IF NOT EXISTS `integers` (          `tiny` tinyint(4) NOT NULL,          `tiny_zerofill`...
Decimals        • Fixed Point        • DECIMAL (5,2)Sunday, January 20, 13
Text Datatypes        • CHAR (0 to 255)        • VARCHAR (0 to 65,535) + lengthSunday, January 20, 13
Bigger Text Datatypes        • TINYTEXT        • TEXT        • MEDIUMTEXT        • LONGTEXT        http://dev.mysql.com/do...
Character Sets + Collation        • A Character Set is a set of symbols and        encodings.        • Collation is the se...
Temporal        • DATE        • TIME        • DATETIME        • TIMESTAMP        http://dev.mysql.com/doc/refman/5.5/en/da...
Table Design        • Primary Key        • Compound Keys        • Indexes        http://dev.mysql.com/doc/refman/5.5/en/da...
Querying        • Sakila Database        • DVD Rental Store        http://dev.mysql.com/doc/sakila/en/index.htmlSunday, Ja...
That’s it!      Thank you all for coming!      Feedback is welcome!Sunday, January 20, 13
Upcoming SlideShare
Loading in...5
×

Mysql

770

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
770
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mysql

  1. 1. MySQL Essentials 2012 Chris Henry @chrishnrySunday, January 20, 13
  2. 2. hello.Sunday, January 20, 13
  3. 3. MySQL @ Behance Powers Be.net 17 Dell R710s 120GB XFS Filesystem Percona 5.5Sunday, January 20, 13
  4. 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 256Sunday, January 20, 13
  5. 5. Percona • Why? http://www.percona.com/ • Percona Toolkit http://www.percona.com/software/percona- toolkitSunday, January 20, 13
  6. 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.htmlSunday, January 20, 13
  7. 7. Configuration • table_open_cache • innodb_buffer_pool • max_connections • key_buffer_sizeSunday, January 20, 13
  8. 8. Slow Log my.cnf slow-query-log-file = /var/lib/mysqllogs/slow-log long-query-time = 2Sunday, January 20, 13
  9. 9. Tuning - Easy Wins • skip-name-resolve • Linux SwappinessSunday, January 20, 13
  10. 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. 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. 12. Table Design • Data Types • Relations • Normal FormSunday, January 20, 13
  13. 13. Data Types • Right tool for the job • Numeric • String • Temporal • SpatialSunday, January 20, 13
  14. 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. 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. 16. Decimals • Fixed Point • DECIMAL (5,2)Sunday, January 20, 13
  17. 17. Text Datatypes • CHAR (0 to 255) • VARCHAR (0 to 65,535) + lengthSunday, January 20, 13
  18. 18. Bigger Text Datatypes • TINYTEXT • TEXT • MEDIUMTEXT • LONGTEXT http://dev.mysql.com/doc/refman/5.5/en/string-type-overview.htmlSunday, January 20, 13
  19. 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. 20. Temporal • DATE • TIME • DATETIME • TIMESTAMP http://dev.mysql.com/doc/refman/5.5/en/date-and-time-types.htmlSunday, January 20, 13
  21. 21. Table Design • Primary Key • Compound Keys • Indexes http://dev.mysql.com/doc/refman/5.5/en/date-and-time-types.htmlSunday, January 20, 13
  22. 22. Querying • Sakila Database • DVD Rental Store http://dev.mysql.com/doc/sakila/en/index.htmlSunday, January 20, 13
  23. 23. That’s it! Thank you all for coming! Feedback is welcome!Sunday, January 20, 13
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×