Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MySQL techtalk

MySQL techtalk

Openminds MySQL techtalk van 18 januari 2011

Bernard Grymonpon

January 19, 2012
Tweet

More Decks by Bernard Grymonpon

Other Decks in Technology

Transcript

  1. Historiek •94 - start •00 - 3.23 release •2008 -

    Sun •2010 - Oracle Thursday 19 January 2012
  2. Versie-soep •MySQL - De Oracle versie •MariaDB - Monty’s versie

    •Percona - Performance versie •OurDelta - patchwork •Drizzle - stripped down Thursday 19 January 2012
  3. Technologie •C/C++ •Unix / Solaris / Windows / ... •Lexer

    - yacc •API’s naar .NET, PHP, Ruby, Java, ... Thursday 19 January 2012
  4. SQL standaard •Niet compatible •Triggers maar één voor en één

    na de query •Geen triggers op views Thursday 19 January 2012
  5. Storage •Default zal goed genoeg zijn •Kan aangepast worden •Foute

    keuze kan dus rechtgezet worden Thursday 19 January 2012
  6. mysqldump --opt databasenaam > datafile.sql mysql databasenaam < datafile.sql mysqldump

    --opt databasenaam | gzip > datafile.sql.gz zcat datafile.sql.gz | mysql databasenaam Thursday 19 January 2012
  7. SELECT ... FROM ... JOIN ... WHERE ... AND/OR/... GROUP

    BY ... HAVING ... ORDER BY ... Thursday 19 January 2012
  8. SELECT * FROM employee FULL OUTER JOIN department ON employee.DepartmentID

    = department.DepartmentID Thursday 19 January 2012
  9. SELECT * FROM employee FULL OUTER JOIN department ON employee.DepartmentID

    = department.DepartmentID Thursday 19 January 2012
  10. SELECT * FROM employee LEFT OUTER JOIN department ON employee.DepartmentID

    = department.DepartmentID Thursday 19 January 2012
  11. SELECT * FROM employee LEFT OUTER JOIN department ON employee.DepartmentID

    = department.DepartmentID Thursday 19 January 2012
  12. MySQL & snelheid •Dataset zo snel mogelijk doorzoeken •Dataset zo

    klein mogelijk houden Thursday 19 January 2012
  13. SHOW INDEXES FROM comments; +----------+------------+----------+--------------+-------------+... | Table | Non_unique |

    Key_name | Seq_in_index | Column_name |... +----------+------------+----------+--------------+-------------+... | comments | 0 | PRIMARY | 1 | id |... +----------+------------+----------+--------------+-------------+... ...+-----------+-------------+----------+--------+------+------------+---------+ ...| Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | ...+-----------+-------------+----------+--------+------+------------+---------+ ...| A | 9294 | NULL | NULL | | BTREE | | ...+-----------+-------------+----------+--------+------+------------+---------+ Thursday 19 January 2012
  14. Indexen •Herberekenen bij insert/update/... •Moeten in-mem zitten om efficiënt te

    zijn •Teveel is ook niet goed Thursday 19 January 2012
  15. +-------------+----------+---------------+------+-------+-------------+ | select_type | table | possible_keys | key |

    rows | Extra | +-------------+----------+---------------+------+-------+-------------+ | SIMPLE | comments | NULL | NULL | 10180 | Using where | +-------------+----------+---------------+------+-------+-------------+ Thursday 19 January 2012
  16. Meerdere kolommen •mysql gebruikt maar één index per tabel •index

    maken over meerdere kolommen Thursday 19 January 2012
  17. select * from tags inner join posts_tags on posts_tags.tag_id =

    tags.id inner join posts on posts.id = posts_tags.post_id inner join comments on comments.post_id = posts.id where posts.author_id = 23 and posts.category_id in (23,5,18) and comments.visible >= 1 and posts.visible >= 1; Thursday 19 January 2012
  18. select * from tags inner join posts_tags on posts_tags.tag_id =

    tags.id inner join posts on posts.id = posts_tags.post_id inner join comments on comments.post_id = posts.id where posts.author_id = 23 and posts.category_id in (23,5,18) and comments.visible >= 1 and posts.visible >= 1; Thursday 19 January 2012
  19. select * from tags inner join posts_tags on posts_tags.tag_id =

    tags.id inner join posts on posts.id = posts_tags.post_id inner join comments on comments.post_id = posts.id where posts.author_id = 23 and posts.category_id in (23,5,18) and comments.visible >= 1 and posts.visible >= 1; Thursday 19 January 2012
  20. select * from tags inner join posts_tags on posts_tags.tag_id =

    tags.id inner join posts on posts.id = posts_tags.post_id inner join comments on comments.post_id = posts.id where posts.author_id = 23 and posts.category_id in (23,5,18) and comments.visible >= 1 and posts.visible >= 1; Thursday 19 January 2012
  21. String-zoeken •Titel die begint met “van” (“van%”) •Titel die eindigt

    met “van” (“%van”) •Titel die “van” bevat (“%van%”) Thursday 19 January 2012
  22. select * from posts where category like ‘%,52,%’ or category

    like ’52,%’ or category like ‘%,52’; Thursday 19 January 2012
  23. <?php $posts = mysql_query(‘select * from posts where stamp >

    NOW()‘); ... Thursday 19 January 2012
  24. select max(id) from posts; ... ... php-code ... select *

    from posts where id in (34,65,78,123,453); Thursday 19 January 2012
  25. charset trouble •charsets zijn overal (connectie, db, schema, ...) •export

    / import meeste probleem •collations (duitse SS!) Thursday 19 January 2012