MySQL Э.Насанжаргал

3,416
-1

Published on

Published in: Technology, Business
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total Views
3,416
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

MySQL Э.Насанжаргал

  1. 1. MYSQL Програмист Э.Насанжаргал
  2. 2. MySQL тухай• 1995 оны 5 сард анх зах зээлд гарсан• C / C++• Хөгжүүлэгч нь MySQL AB• Facebook, Google, Wikipedia …
  3. 3. MySQL versions
  4. 4. MySQL versions
  5. 5. MySQL query бичихэданхаарах зүйлс• Түгээмэл алдаанууд • Limit ашиглах • Олон давхар Join ашигласан үед бүх баганыг Select хийх SELECT * FROM sakila.actor INNER JOIN salila.film_actor USING (actor_id) INNER JOIN salila.film USING (film_id) WHERE sakila.film.title = Academy Dinosaur;
  6. 6. MySQL query бичихэданхаарах зүйлс • Бүх баганыг Select хийх SELECT * • Count(*) => Count(column_name) • Unique row SELECT 1 FROM user WHERE state = Alabama LIMIT 1 • Order by RAND() • ENUM ийг тогтмол тэмдэгттэй vед VARCHAR
  7. 7. Join Decomposition• SELECT * FROM tag JOIN tag_post ON tag_post.tag_id=tag.id JOIN post ON tag_post.post_id=post.id WHERE tag.tag=mysql;• SELECT * FROM tag WHERE tag=mysql; SELECT * FROM tag_post WHERE tag_id=1234; SELECT * FROM post WHERE post.id in (123,456,567,9098,8904);
  8. 8. Хэрвээ Join ийг илүү хурдан, ашигтайажлуулъя гэвэл• Query Cache ашиглах• MyISAM engine – тай хүснэгт ашиглах• Олон сервер ашиглах• Join ийг In() солих – Том хэмжээтэй хүснэгтэнд
  9. 9. Unbuffered query• mysql_connect("localhost", "php", "alm65z"); mysql_select_db("phpdb"); $result = mysql_unbuffered_query("SELECT ID, Name FROM conferences;"); $result = mysql_query("SELECT ID, Name FROM conferences;"); while ($row = mysql_fetch_assoc($result)) { extract($row, EXTR_PREFIX_ALL, "conf"); print "$conf_Namen"; }
  10. 10. Chopping up a QueryMysql> DELETE FROM messages WHERE created < DATE_SUB(NOW(),INTERVAL 3 month)rows_affected = 0do{rows_affected = do_query( DELETE FROM messages WHERE created < DATE_SUB(NOW(),INTERVAL 3 month) LIMIT 10000 )} while rows_affected > 0
  11. 11. Query Cache// query cache does NOT work$r = mysql_query("SELECT username FROM user WHERE signup_date >= CURDATE()");// query cache works!$today = date("Y-m-d");$r = mysql_query("SELECT username FROM user WHERE signup_date >= $today");
  12. 12. Index the Search FieldsMysql> Select count(1) From users Where last_name Like ‘a%’; 0.25Mysql> Alter table ‘users’ Add index(‘last_name’);Mysql> Select count(1) From users Where last_name Like ‘a%’; 0.06Count == 63285
  13. 13. Index use for JoinSELECT company_name FROM users LEFT JOIN companies ON (users.state = companies.state) WHERE users.id = 15 users.state - индекслэгдсэн багана
  14. 14. Procedure Analyse(max_element, max_memory) • SELECT quantity, sale_order_id FROM `sale_order_queue` PROCEDURE ANALYSE ( 1000000, 256 )
  15. 15. IP Addresses as Unsigned int UPDATE users SET ip = INET_ATON ({$_SERVER[REMOTE_ADDR]}) WHERE user_id =15 192.168.1.100 INET_NTOA() , ip2long() , long2ip()
  16. 16. Partition • CREATE TABLE ti (id INT, amount DECIMAL(7,2), tr_date DATE) ENGINE=INNODB PARTITION BY HASH( MONTH(tr_date) ) PARTITIONS 6; • Partition type • Hash • Range • List • Key
  17. 17. Range
  18. 18. Hash
  19. 19. Key
  20. 20. List
  21. 21. Partition ашиглах • CREATE TABLE ts1 ( • c1 INT, • c2 VARCHAR(20) • ) • PARTITION BY LIST(c1) ( • PARTITION p0 VALUES IN (0, 3, 6), • PARTITION p1 VALUES IN (1, 4, 7), • PARTITION p2 VALUES IN (2, 5, 8) • ); • INSERT INTO ts1 VALUES (8, mothra); • c1 c2 8 mothra
  22. 22. Анхаарал тавьсанд Баярлалаа

×