Mysql

  • 524 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
524
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
17
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. MySQL Essentials 2012 Chris Henry @chrishnrySunday, January 20, 13
  • 2. hello.Sunday, January 20, 13
  • 3. MySQL @ Behance Powers Be.net 17 Dell R710s 120GB XFS Filesystem Percona 5.5Sunday, 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 256Sunday, January 20, 13
  • 5. Percona • Why? http://www.percona.com/ • Percona Toolkit http://www.percona.com/software/percona- toolkitSunday, 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.htmlSunday, January 20, 13
  • 7. Configuration • table_open_cache • innodb_buffer_pool • max_connections • key_buffer_sizeSunday, January 20, 13
  • 8. Slow Log my.cnf slow-query-log-file = /var/lib/mysqllogs/slow-log long-query-time = 2Sunday, January 20, 13
  • 9. Tuning - Easy Wins • skip-name-resolve • Linux SwappinessSunday, 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 FormSunday, January 20, 13
  • 13. Data Types • Right tool for the job • Numeric • String • Temporal • SpatialSunday, 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) + lengthSunday, January 20, 13
  • 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. 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.htmlSunday, January 20, 13
  • 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. Querying • Sakila Database • DVD Rental Store http://dev.mysql.com/doc/sakila/en/index.htmlSunday, January 20, 13
  • 23. That’s it! Thank you all for coming! Feedback is welcome!Sunday, January 20, 13