{"id":84085,"date":"2025-01-16T15:54:34","date_gmt":"2025-01-16T08:54:34","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=84085"},"modified":"2025-01-16T15:54:34","modified_gmt":"2025-01-16T08:54:34","slug":"cau-hoi-phong-van-mysql","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/","title":{"rendered":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#MySQL_la_gi\" >MySQL l\u00e0 g\u00ec?\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#Nhung_ai_can_biet_cau_hoi_phong_van_MySQL\" >Nh\u1eefng ai c\u1ea7n bi\u1ebft c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#Cac_cau_hoi_phong_van_MySQL_thuong_gap_danh_cho_Fresher\" >C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL th\u01b0\u1eddng g\u1eb7p d\u00e0nh cho Fresher\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#Cac_cau_hoi_phong_van_MySQL_thuong_gap_danh_cho_Intermediate\" >C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL th\u01b0\u1eddng g\u1eb7p d\u00e0nh cho Intermediate<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#Cac_cau_hoi_phong_van_MySQL_danh_cho_Advanced\" >C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL d\u00e0nh cho Advanced<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#Tong_ket_cau_hoi_phong_van_MySQL\" >T\u1ed5ng k\u1ebft c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>MySQL l\u00e0 m\u1ed9t trong nh\u1eefng h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u ph\u1ed5 bi\u1ebfn nh\u1ea5t, \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng r\u1ed9ng r\u00e3i trong c\u00e1c \u1ee9ng d\u1ee5ng t\u1eeb nh\u1ecf \u0111\u1ebfn l\u1edbn, n\u00ean s\u1ebd th\u01b0\u1eddng xu\u1ea5t hi\u1ec7n trong c\u00e1c bu\u1ed5i ph\u1ecfng v\u1ea5n li\u00ean quan \u0111\u1ebfn c\u01a1 s\u1edf d\u1eef li\u1ec7u. Danh s\u00e1ch 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL sau \u0111\u00e2y s\u1ebd gi\u00fap b\u1ea1n n\u1eafm v\u1eefng kh\u00f4ng ch\u1ec9 c\u00e1c ki\u1ebfn th\u1ee9c c\u01a1 b\u1ea3n m\u00e0 c\u00f2n c\u1ea3 c\u00e1c kh\u00eda c\u1ea1nh n\u00e2ng cao nh\u01b0 t\u1ed1i \u01b0u h\u00f3a truy v\u1ea5n, l\u1eadp ch\u1ec9 m\u1ee5c, ho\u1eb7c thi\u1ebft k\u1ebf c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/strong><\/em><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3 hi\u1ec3u r\u00f5 h\u01a1n v\u1ec1:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL d\u00e0nh cho Fresher<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL d\u00e0nh cho Intermediate<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL d\u00e0nh cho Advanced<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"MySQL_la_gi\"><\/span><b>MySQL l\u00e0 g\u00ec?\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">MySQL l\u00e0 m\u1ed9t h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 m\u00e3 ngu\u1ed3n m\u1edf (Relational Database Management System &#8211; RDBMS), \u0111\u01b0\u1ee3c ph\u00e1t tri\u1ec3n b\u1edfi c\u00f4ng ty MySQL AB v\u00e0o n\u0103m 1995 v\u00e0 sau \u0111\u00f3 \u0111\u01b0\u1ee3c Oracle Corporation mua l\u1ea1i v\u00e0o n\u0103m 2010.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 m\u1ed9t trong nh\u1eefng h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd c\u01a1 s\u1edf d\u1eef li\u1ec7u ph\u1ed5 bi\u1ebfn nh\u1ea5t tr\u00ean th\u1ebf gi\u1edbi, \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng r\u1ed9ng r\u00e3i trong c\u00e1c \u1ee9ng d\u1ee5ng web, doanh nghi\u1ec7p v\u00e0 ph\u1ea7n m\u1ec1m.<\/span><\/p>\n<h3><b>\u0110\u1eb7c \u0111i\u1ec3m ch\u00ednh c\u1ee7a MySQL<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ki\u1ebfn tr\u00fac c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 (Relational Database):<\/b><span style=\"font-weight: 400;\"> MySQL t\u1ed5 ch\u1ee9c d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng b\u1ea3ng (table) v\u1edbi c\u00e1c h\u00e0ng (rows) v\u00e0 c\u1ed9t (columns), gi\u00fap \u0111\u1ea3m b\u1ea3o t\u00ednh nh\u1ea5t qu\u00e1n v\u00e0 d\u1ec5 d\u00e0ng trong vi\u1ec7c thao t\u00e1c, qu\u1ea3n l\u00fd d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>M\u00e3 ngu\u1ed3n m\u1edf v\u00e0 mi\u1ec5n ph\u00ed:<\/b><span style=\"font-weight: 400;\"> MySQL \u0111\u01b0\u1ee3c ph\u00e1t h\u00e0nh theo gi\u1ea5y ph\u00e9p GNU General Public License (GPL), cho ph\u00e9p ng\u01b0\u1eddi d\u00f9ng s\u1eed d\u1ee5ng mi\u1ec5n ph\u00ed trong h\u1ea7u h\u1ebft c\u00e1c \u1ee9ng d\u1ee5ng. Ngo\u00e0i ra, Oracle c\u0169ng cung c\u1ea5p phi\u00ean b\u1ea3n MySQL th\u01b0\u01a1ng m\u1ea1i v\u1edbi c\u00e1c t\u00ednh n\u0103ng m\u1edf r\u1ed9ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>H\u1ed7 tr\u1ee3 \u0111a n\u1ec1n t\u1ea3ng:<\/b><span style=\"font-weight: 400;\"> MySQL ho\u1ea1t \u0111\u1ed9ng tr\u00ean nhi\u1ec1u h\u1ec7 \u0111i\u1ec1u h\u00e0nh bao g\u1ed3m Windows, Linux, macOS v\u00e0 Unix, gi\u00fap d\u1ec5 d\u00e0ng t\u00edch h\u1ee3p v\u00e0o c\u00e1c h\u1ec7 th\u1ed1ng kh\u00e1c nhau.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Hi\u1ec7u su\u1ea5t cao:<\/b><span style=\"font-weight: 400;\"> MySQL \u0111\u01b0\u1ee3c t\u1ed1i \u01b0u h\u00f3a \u0111\u1ec3 x\u1eed l\u00fd kh\u1ed1i l\u01b0\u1ee3ng l\u1edbn d\u1eef li\u1ec7u v\u1edbi t\u1ed1c \u0111\u1ed9 cao, \u0111\u1eb7c bi\u1ec7t ph\u00f9 h\u1ee3p v\u1edbi c\u00e1c \u1ee9ng d\u1ee5ng web l\u1edbn.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cung c\u1ea5p nhi\u1ec1u t\u00ednh n\u0103ng b\u1ea3o m\u1eadt v\u00e0 qu\u1ea3n l\u00fd ng\u01b0\u1eddi d\u00f9ng:<\/b><span style=\"font-weight: 400;\"> MySQL h\u1ed7 tr\u1ee3 c\u00e1c t\u00ednh n\u0103ng b\u1ea3o m\u1eadt nh\u01b0 m\u00e3 h\u00f3a d\u1eef li\u1ec7u, SSL \u0111\u1ec3 b\u1ea3o v\u1ec7 k\u1ebft n\u1ed1i, c\u00f9ng kh\u1ea3 n\u0103ng qu\u1ea3n l\u00fd quy\u1ec1n truy c\u1eadp chi ti\u1ebft cho t\u1eebng ng\u01b0\u1eddi d\u00f9ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>H\u1ed7 tr\u1ee3 ch\u1ebf \u0111\u1ed9 \u0111\u1ed3ng b\u1ed9 v\u00e0 b\u1ea5t \u0111\u1ed3ng b\u1ed9 trong qu\u1ea3n l\u00fd d\u1eef li\u1ec7u:<\/b><span style=\"font-weight: 400;\"> MySQL cung c\u1ea5p kh\u1ea3 n\u0103ng replication d\u1eef li\u1ec7u gi\u1eefa c\u00e1c m\u00e1y ch\u1ee7, cho ph\u00e9p ng\u01b0\u1eddi d\u00f9ng l\u1ef1a ch\u1ecdn gi\u1eefa ch\u1ebf \u0111\u1ed9 \u0111\u1ed3ng b\u1ed9 v\u00e0 b\u1ea5t \u0111\u1ed3ng b\u1ed9, \u0111\u00e1p \u1ee9ng c\u00e1c y\u00eau c\u1ea7u kh\u00e1c nhau v\u1ec1 hi\u1ec7u n\u0103ng v\u00e0 t\u00ednh nh\u1ea5t qu\u00e1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Sao l\u01b0u v\u00e0 ph\u1ee5c h\u1ed3i:<\/b><span style=\"font-weight: 400;\"> MySQL h\u1ed7 tr\u1ee3 c\u00e1c c\u00f4ng c\u1ee5 sao l\u01b0u d\u1eef li\u1ec7u linh ho\u1ea1t v\u00e0 ph\u1ee5c h\u1ed3i nhanh ch\u00f3ng, gi\u00fap \u0111\u1ea3m b\u1ea3o an to\u00e0n cho d\u1eef li\u1ec7u trong c\u00e1c t\u00ecnh hu\u1ed1ng l\u1ed7i ho\u1eb7c m\u1ea5t d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Kh\u1ea3 n\u0103ng t\u00edch h\u1ee3p v\u1edbi nhi\u1ec1u ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh:<\/b><span style=\"font-weight: 400;\"> MySQL c\u00f3 th\u1ec3 t\u00edch h\u1ee3p t\u1ed1t v\u1edbi nhi\u1ec1u lo\u1ea1i ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh nh\u01b0 PHP, Python, Java, C++, .NET, gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean d\u1ec5 d\u00e0ng tri\u1ec3n khai v\u00e0 ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng.<\/span><\/li>\n<\/ul>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-sql\/\" target=\"_blank\" rel=\"noopener\"><strong>Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n SQL ph\u1ed5 bi\u1ebfn nh\u1ea5t<\/strong><\/a><\/em><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Nhung_ai_can_biet_cau_hoi_phong_van_MySQL\"><\/span><b>Nh\u1eefng ai c\u1ea7n bi\u1ebft c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Vi\u1ec7c n\u1eafm b\u1eaft c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL kh\u00f4ng ch\u1ec9 quan tr\u1ecdng \u0111\u1ed1i v\u1edbi \u1ee9ng vi\u00ean m\u00e0 c\u00f2n mang l\u1ea1i l\u1ee3i \u00edch cho nhi\u1ec1u nh\u00f3m \u0111\u1ed1i t\u01b0\u1ee3ng kh\u00e1c nhau nh\u01b0:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u1ee8ng vi\u00ean \u0111ang t\u00ecm vi\u1ec7c trong l\u0129nh v\u1ef1c IT<\/b>, nh\u01b0:<\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>L\u1eadp tr\u00ecnh vi\u00ean Backend ho\u1eb7c Full-Stack: <\/b><span style=\"font-weight: 400;\">Nh\u1eefng ng\u01b0\u1eddi l\u00e0m vi\u1ec7c v\u1edbi c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 nh\u01b0 MySQL c\u1ea7n chu\u1ea9n b\u1ecb cho c\u00e1c c\u00e2u h\u1ecfi v\u1ec1 truy v\u1ea5n SQL, t\u1ed1i \u01b0u h\u00f3a c\u01a1 s\u1edf d\u1eef li\u1ec7u, v\u00e0 x\u1eed l\u00fd l\u1ed7i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Qu\u1ea3n tr\u1ecb vi\u00ean c\u01a1 s\u1edf d\u1eef li\u1ec7u (DBA &#8211; Database Administrator)<\/b><span style=\"font-weight: 400;\">: H\u1ecd c\u1ea7n hi\u1ec3u s\u00e2u v\u1ec1 MySQL \u0111\u1ec3 tr\u1ea3 l\u1eddi c\u00e1c c\u00e2u h\u1ecfi li\u00ean quan \u0111\u1ebfn b\u1ea3o m\u1eadt, sao l\u01b0u, replication, v\u00e0 t\u1ed1i \u01b0u h\u00f3a hi\u1ec7u su\u1ea5t.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Nh\u00e0 ph\u00e2n t\u00edch d\u1eef li\u1ec7u (Data Analysts)<\/b><span style=\"font-weight: 400;\">: Nh\u1eefng ng\u01b0\u1eddi s\u1eed d\u1ee5ng MySQL \u0111\u1ec3 ph\u00e2n t\u00edch v\u00e0 tr\u1ef1c quan h\u00f3a d\u1eef li\u1ec7u c\u0169ng c\u1ea7n bi\u1ebft c\u00e1ch vi\u1ebft c\u00e1c truy v\u1ea5n hi\u1ec7u qu\u1ea3.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Nh\u00e0 tuy\u1ec3n d\u1ee5ng v\u00e0 ng\u01b0\u1eddi ph\u1ecfng v\u1ea5n<\/b><span style=\"font-weight: 400;\">: Nh\u1eefng ng\u01b0\u1eddi l\u00e0m vi\u1ec7c trong vai tr\u00f2 tuy\u1ec3n d\u1ee5ng c\u1ea7n chu\u1ea9n b\u1ecb c\u00e1c c\u00e2u h\u1ecfi ph\u00f9 h\u1ee3p \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh m\u1ee9c \u0111\u1ed9 th\u00e0nh th\u1ea1o c\u1ee7a \u1ee9ng vi\u00ean, \u0111\u1eb7c bi\u1ec7t khi c\u00f4ng ty s\u1eed d\u1ee5ng MySQL trong d\u1ef1 \u00e1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Sinh vi\u00ean v\u00e0 ng\u01b0\u1eddi h\u1ecdc c\u00f4ng ngh\u1ec7<\/b><span style=\"font-weight: 400;\">: Sinh vi\u00ean nh\u1eefng ng\u00e0nh v\u1ec1 C\u00f4ng ngh\u1ec7 Th\u00f4ng tin n\u00ean chu\u1ea9n b\u1ecb ki\u1ebfn th\u1ee9c MySQL \u0111\u1ec3 ho\u00e0n thi\u1ec7n k\u1ef9 n\u0103ng c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u1ee7a m\u00ecnh. Ngo\u00e0i ra, nh\u1eefng ng\u01b0\u1eddi t\u1ef1 h\u1ecdc l\u1eadp tr\u00ecnh mu\u1ed1n n\u1eafm ch\u1eafc c\u00e1c k\u1ef9 n\u0103ng th\u1ef1c t\u1ebf c\u0169ng n\u00ean bi\u1ebft c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n \u0111\u1ec3 ki\u1ec3m tra \u0111\u1ec3 c\u1ee7ng c\u1ed1 ki\u1ebfn th\u1ee9c.<\/span><\/li>\n<\/ul>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam:\u00a0<\/em><a href=\"https:\/\/itviec.com\/blog\/lo-trinh-hoc-mysql-co-ban\/\" target=\"_blank\" rel=\"noopener\"><strong>H\u1ecdc MySQL c\u01a1 b\u1ea3n v\u1edbi l\u1ed9 tr\u00ecnh v\u00e0 t\u00e0i li\u1ec7u t\u1ed5ng quan<\/strong><\/a><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Cac_cau_hoi_phong_van_MySQL_thuong_gap_danh_cho_Fresher\"><\/span><b>C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL th\u01b0\u1eddng g\u1eb7p d\u00e0nh cho Fresher\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>MySQL kh\u00e1c g\u00ec so v\u1edbi c\u00e1c RDBMS kh\u00e1c?<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>MySQL<\/b><\/td>\n<td><b>PostgreSQL<\/b><\/td>\n<td><b>Oracle<\/b><\/td>\n<td><b>SQL Server<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">M\u00e3 ngu\u1ed3n<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u00e3 ngu\u1ed3n m\u1edf (Community Edition); c\u00f3 b\u1ea3n tr\u1ea3 ph\u00ed (Enterprise Edition)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u00e3 ngu\u1ed3n m\u1edf<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ed9c quy\u1ec1n, thu\u1ed9c s\u1edf h\u1eefu c\u1ee7a Oracle Corporation<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 phi\u00ean b\u1ea3n mi\u1ec5n ph\u00ed (Express) v\u00e0 b\u1ea3n tr\u1ea3 ph\u00ed, thu\u1ed9c s\u1edf h\u1eefu c\u1ee7a Microsoft<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hi\u1ec7u n\u0103ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ed1i \u01b0u cho c\u00e1c truy v\u1ea5n \u0111\u01a1n gi\u1ea3n, hi\u1ec7u su\u1ea5t cao v\u1edbi kh\u1ed1i l\u01b0\u1ee3ng d\u1eef li\u1ec7u l\u1edbn<\/span><\/td>\n<td><span style=\"font-weight: 400;\">X\u1eed l\u00fd t\u1ed1t c\u00e1c truy v\u1ea5n ph\u1ee9c t\u1ea1p, h\u1ed7 tr\u1ee3 giao d\u1ecbch n\u1eb7ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 x\u1eed l\u00fd kh\u1ed1i l\u01b0\u1ee3ng d\u1eef li\u1ec7u r\u1ea5t l\u1edbn trong th\u1eddi gian th\u1ef1c<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Hi\u1ec7u su\u1ea5t cao khi t\u00edch h\u1ee3p trong h\u1ec7 sinh th\u00e1i Microsoft<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">T\u00ednh n\u0103ng n\u1ed5i b\u1eadt<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; D\u1ec5 s\u1eed d\u1ee5ng, th\u00e2n thi\u1ec7n v\u1edbi ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 Replication, Sharding<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; InnoDB \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 m\u1ea1nh m\u1ebd c\u00e1c t\u00ednh n\u0103ng n\u00e2ng cao nh\u01b0 Window Functions, CTE, JSON<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Tu\u00e2n th\u1ee7 chu\u1ea9n SQL t\u1ed1t h\u01a1n<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; T\u00ednh n\u0103ng m\u1ea1nh m\u1ebd cho doanh nghi\u1ec7p nh\u01b0 RAC (Real Application Clusters), Partitioning<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u1ea3 n\u0103ng b\u1ea3o m\u1eadt cao<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; T\u00edch h\u1ee3p t\u1ed1t v\u1edbi h\u1ec7 sinh th\u00e1i Microsoft (.NET, Azure)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 c\u00f4ng c\u1ee5 b\u00e1o c\u00e1o v\u00e0 ph\u00e2n t\u00edch d\u1eef li\u1ec7u m\u1ea1nh m\u1ebd<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u00f9 h\u1ee3p v\u1edbi \u1ee9ng d\u1ee5ng v\u1eeba v\u00e0 nh\u1ecf, h\u1ed7 tr\u1ee3 sharding v\u00e0 replication<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng cao, h\u1ed7 tr\u1ee3 sharding v\u00e0 replication<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng r\u1ea5t cao, h\u1ed7 tr\u1ee3 clustering ph\u1ee9c t\u1ea1p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng t\u1ed1t, h\u1ed7 tr\u1ee3 clustering v\u00e0 replication<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">N\u1ec1n t\u1ea3ng h\u1ed7 tr\u1ee3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Windows, Linux, macOS, Unix<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Windows, Linux, macOS, Unix<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Windows, Linux, Unix<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Windows, Linux<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Ph\u00f9 h\u1ee3p cho \u1ee9ng d\u1ee5ng web, th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; C\u00e1c h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd v\u1eeba v\u00e0 nh\u1ecf<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Th\u00edch h\u1ee3p v\u1edbi doanh nghi\u1ec7p v\u1eeba v\u00e0 l\u1edbn<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; \u1ee8ng d\u1ee5ng cho h\u1ec7 th\u1ed1ng t\u00e0i ch\u00ednh, ph\u00e2n t\u00edch d\u1eef li\u1ec7u l\u1edbn<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; D\u00e0nh cho c\u00e1c doanh nghi\u1ec7p l\u1edbn, t\u1eadp \u0111o\u00e0n<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; H\u1ec7 th\u1ed1ng ERP, CRM v\u00e0 ph\u00e2n t\u00edch d\u1eef li\u1ec7u ph\u1ee9c t\u1ea1p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; H\u1ec7 th\u1ed1ng doanh nghi\u1ec7p v\u1eeba v\u00e0 l\u1edbn<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; \u1ee8ng d\u1ee5ng trong ng\u00e0nh t\u00e0i ch\u00ednh, ng\u00e2n h\u00e0ng, qu\u1ea3n tr\u1ecb doanh nghi\u1ec7p<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u1ed9ng \u0111\u1ed3ng h\u1ed7 tr\u1ee3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; C\u1ed9ng \u0111\u1ed3ng l\u1edbn, nhi\u1ec1u t\u00e0i li\u1ec7u v\u00e0 di\u1ec5n \u0111\u00e0n h\u1ed7 tr\u1ee3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Nhi\u1ec1u plugin v\u00e0 c\u00f4ng c\u1ee5 b\u1ed5 tr\u1ee3 mi\u1ec5n ph\u00ed<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u1ed9ng \u0111\u1ed3ng n\u0103ng \u0111\u1ed9ng, th\u01b0\u1eddng xuy\u00ean c\u1eadp nh\u1eadt t\u00ednh n\u0103ng m\u1edbi<\/span><\/td>\n<td><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3 ch\u1ee7 y\u1ebfu t\u1eeb Oracle, c\u1ed9ng \u0111\u1ed3ng nh\u1ecf h\u01a1n nh\u01b0ng nhi\u1ec1u t\u00e0i li\u1ec7u chuy\u00ean s\u00e2u<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u01b0\u1ee3c h\u1ed7 tr\u1ee3 m\u1ea1nh m\u1ebd t\u1eeb Microsoft, h\u1ec7 sinh th\u00e1i b\u1ed5 tr\u1ee3 phong ph\u00fa<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>DML, DDL v\u00e0 DCL l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trong MySQL c\u0169ng nh\u01b0 c\u00e1c h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 kh\u00e1c, c\u00e1c c\u00e2u l\u1ec7nh SQL \u0111\u01b0\u1ee3c chia th\u00e0nh c\u00e1c lo\u1ea1i ch\u00ednh d\u1ef1a tr\u00ean m\u1ee5c \u0111\u00edch s\u1eed d\u1ee5ng. Ba nh\u00f3m ch\u00ednh l\u00e0:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\"> DML (Data Manipulation Language)<\/span><\/li>\n<li><span style=\"font-weight: 400;\">DDL (Data Definition Language)<\/span><\/li>\n<li><span style=\"font-weight: 400;\">DCL (Data Control Language)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">M\u1ed7i nh\u00f3m ph\u1ee5c v\u1ee5 m\u1ed9t m\u1ee5c \u0111\u00edch c\u1ee5 th\u1ec3 trong vi\u1ec7c qu\u1ea3n l\u00fd v\u00e0 thao t\u00e1c d\u1eef li\u1ec7u.<\/span><\/p>\n<h4><b>DML (Data Manipulation Language) &#8211; Ng\u00f4n ng\u1eef thao t\u00e1c d\u1eef li\u1ec7u<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">DML bao g\u1ed3m c\u00e1c l\u1ec7nh d\u00f9ng \u0111\u1ec3 thao t\u00e1c v\u1edbi d\u1eef li\u1ec7u b\u00ean trong b\u1ea3ng gi\u00fap th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c nh\u01b0 th\u00eam, s\u1eeda, x\u00f3a v\u00e0 truy v\u1ea5n d\u1eef li\u1ec7u. DML kh\u00f4ng thay \u0111\u1ed5i c\u1ea5u tr\u00fac c\u1ee7a b\u1ea3ng m\u00e0 ch\u1ec9 thay \u0111\u1ed5i d\u1eef li\u1ec7u trong c\u00e1c b\u1ea3ng. C\u00e1c l\u1ec7nh DML trong MySQL g\u1ed3m:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\">: Truy v\u1ea5n d\u1eef li\u1ec7u t\u1eeb m\u1ed9t ho\u1eb7c nhi\u1ec1u b\u1ea3ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">: Th\u00eam d\u1eef li\u1ec7u m\u1edbi.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">UPDATE<\/span><span style=\"font-weight: 400;\">: C\u1eadp nh\u1eadt d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\">: X\u00f3a d\u1eef li\u1ec7u.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 truy v\u1ea5n d\u1eef li\u1ec7u t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\">, ta dung c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT * FROM employees;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3 <\/span><span style=\"font-weight: 400;\">SELECT *<\/span><span style=\"font-weight: 400;\"> d\u00f9ng \u0111\u1ec3 truy v\u1ea5n t\u1ea5t c\u1ea3 c\u00e1c c\u1ed9t trong m\u1ed9t b\u1ea3ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 th\u00eam d\u1eef li\u1ec7u v\u00e0o b\u1ea3ng ta d\u00f9ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\"> v\u1edbi c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO employees (id, name, age) VALUES (1, 'John Doe', 30);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 xo\u00e1 th\u00f4ng tin c\u1ee7a nh\u00e2n vi\u00ean c\u00f3 <\/span><span style=\"font-weight: 400;\">id=1<\/span><span style=\"font-weight: 400;\"> ra kh\u1ecfi b\u1ea3ng employees, ta d\u00f9ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM employees WHERE id = 1;<\/span><\/pre>\n<blockquote><p>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/ngon-ngu-thao-tac-du-lieu-la-gi\/\" target=\"_blank\" rel=\"noopener\"><strong>Ng\u00f4n ng\u1eef thao t\u00e1c d\u1eef li\u1ec7u (DML) l\u00e0 g\u00ec? C\u00e1c l\u1ec7nh c\u01a1 b\u1ea3n v\u1edbi DML<\/strong><\/a><\/p><\/blockquote>\n<h4><b>DDL &#8211; Data Definition Language (Ng\u00f4n ng\u1eef \u0111\u1ecbnh ngh\u0129a d\u1eef li\u1ec7u)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">DDL l\u00e0 c\u00e1c c\u00e2u l\u1ec7nh SQL \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 \u0111\u1ecbnh ngh\u0129a c\u1ea5u tr\u00fac c\u1ee7a c\u01a1 s\u1edf d\u1eef li\u1ec7u, b\u1ea3ng v\u00e0 c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng kh\u00e1c nh\u01b0 ch\u1ec9 m\u1ee5c (index), r\u00e0ng bu\u1ed9c v\u00e0 quan h\u1ec7 gi\u1eefa c\u00e1c b\u1ea3ng. C\u00e2u l\u1ec7nh DDL gi\u00fap t\u1ea1o m\u1edbi, thay \u0111\u1ed5i ho\u1eb7c x\u00f3a c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/p>\n<blockquote><p><b><i>L\u01b0u \u00fd l\u00e0 DDL l\u00e0m thay \u0111\u1ed5i c\u1ea5u tr\u00fac c\u1ee7a c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 th\u01b0\u1eddng kh\u00f4ng th\u1ec3 ho\u00e0n t\u00e1c (rollback) nh\u01b0 DML.<\/i><\/b><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u l\u1ec7nh DDL trong MySQL bao g\u1ed3m:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">CREATE<\/span><span style=\"font-weight: 400;\">: T\u1ea1o c\u01a1 s\u1edf d\u1eef li\u1ec7u, b\u1ea3ng, view ho\u1eb7c c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng kh\u00e1c.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">ALTER<\/span><span style=\"font-weight: 400;\">: S\u1eeda \u0111\u1ed5i c\u1ea5u tr\u00fac c\u1ee7a b\u1ea3ng ho\u1eb7c c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">DROP<\/span><span style=\"font-weight: 400;\">: X\u00f3a b\u1ea3ng, c\u01a1 s\u1edf d\u1eef li\u1ec7u ho\u1eb7c c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng kh\u00e1c.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">TRUNCATE<\/span><span style=\"font-weight: 400;\">: X\u00f3a to\u00e0n b\u1ed9 d\u1eef li\u1ec7u trong b\u1ea3ng nh\u01b0ng gi\u1eef nguy\u00ean c\u1ea5u tr\u00fac.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u1ea1o m\u1ed9t b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> d\u00f9ng \u0111\u1ec3 l\u01b0u tr\u1eef th\u00f4ng tin c\u1ee7a nh\u00e2n vi\u00ean, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TABLE employees (\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0id INT PRIMARY KEY,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0name VARCHAR(100),<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0age INT\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 th\u00eam c\u1ed9t address \u0111\u1ec3 l\u01b0u tr\u1eef \u0111\u1ecba ch\u1ec9 c\u1ee7a nh\u00e2n vi\u00ean trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\">, ta d\u00f9ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">ALTER<\/span><span style=\"font-weight: 400;\"> v\u1edbi c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">ALTER TABLE employees ADD COLUMN address VARCHAR(255);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 xo\u00e1 b\u1ea3ng employees ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DROP TABLE employees;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 xo\u00e1 d\u1eef li\u1ec7u trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> nh\u01b0ng kh\u00f4ng xo\u00e1 b\u1ea3ng, ta s\u1eed d\u1ee5ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">TRUNCATE<\/span><span style=\"font-weight: 400;\"> v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">TRUNCATE TABLE employees;<\/span><\/pre>\n<blockquote><p>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/ngon-ngu-dinh-nghia-du-lieu-la-gi\/\" target=\"_blank\" rel=\"noopener\"><strong>Ng\u00f4n ng\u1eef \u0111\u1ecbnh ngh\u0129a d\u1eef li\u1ec7u l\u00e0 g\u00ec? C\u00e1c l\u1ec7nh DDL c\u01a1 b\u1ea3n<\/strong><\/a><\/p><\/blockquote>\n<h4><b>DCL &#8211; Data Control Language (Ng\u00f4n ng\u1eef \u0111i\u1ec1u khi\u1ec3n d\u1eef li\u1ec7u)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">DCL l\u00e0 c\u00e1c c\u00e2u l\u1ec7nh SQL \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 ki\u1ec3m so\u00e1t quy\u1ec1n truy c\u1eadp v\u00e0o d\u1eef li\u1ec7u v\u00e0 c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. C\u00e1c c\u00e2u l\u1ec7nh DCL gi\u00fap x\u00e1c \u0111\u1ecbnh quy\u1ec1n h\u1ea1n c\u1ee7a ng\u01b0\u1eddi d\u00f9ng v\u00e0 c\u1ea5p ho\u1eb7c thu h\u1ed3i quy\u1ec1n s\u1eed d\u1ee5ng c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1c c\u00e2u l\u1ec7nh DCL trong MySQL bao g\u1ed3m:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">GRANT<\/span><span style=\"font-weight: 400;\">: C\u1ea5p quy\u1ec1n cho ng\u01b0\u1eddi d\u00f9ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">REVOKE<\/span><span style=\"font-weight: 400;\">: Thu h\u1ed3i quy\u1ec1n t\u1eeb ng\u01b0\u1eddi d\u00f9ng.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 c\u1ea5p quy\u1ec1n SELECT v\u00e0 INSERT cho ng\u01b0\u1eddi d\u00f9ng, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">GRANT SELECT, INSERT ON employees TO 'user'@'localhost';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 thu h\u1ed3i quy\u1ec1n <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\"> c\u1ee7a ng\u01b0\u1eddi d\u00f9ng tr\u00ean b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\">, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">REVOKE INSERT ON employees FROM 'user'@'localhost';<\/span><\/pre>\n<h3><b>Ph\u00e2n bi\u1ec7t <\/b><b>CHAR v\u00e0 VARCHAR nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">CHAR v\u00e0 VARCHAR l\u00e0 hai ki\u1ec3u d\u1eef li\u1ec7u ph\u1ed5 bi\u1ebfn trong c\u00e1c h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u, \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 l\u01b0u tr\u1eef chu\u1ed7i k\u00fd t\u1ef1. M\u1eb7c d\u00f9 c\u1ea3 hai \u0111\u1ec1u x\u1eed l\u00fd d\u1eef li\u1ec7u d\u1ea1ng text, ch\u00fang c\u00f3 s\u1ef1 kh\u00e1c bi\u1ec7t r\u00f5 r\u1ec7t v\u1ec1 c\u00e1ch l\u01b0u tr\u1eef v\u00e0 hi\u1ec7u su\u1ea5t.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 b\u1ea3ng so s\u00e1nh c\u1ee7a 2 ki\u1ec3u d\u1eef li\u1ec7u n\u00e0y:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>CHAR<\/b><\/td>\n<td><b>VARCHAR<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Ki\u1ec3u l\u01b0u tr\u1eef<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u c\u00f3 \u0111\u1ed9 d\u00e0i c\u1ed1 \u0111\u1ecbnh.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u c\u00f3 \u0111\u1ed9 d\u00e0i thay \u0111\u1ed5i.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Dung l\u01b0\u1ee3ng l\u01b0u tr\u1eef<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ed1n dung l\u01b0\u1ee3ng c\u1ed1 \u0111\u1ecbnh s\u1ed1 byte theo \u0111\u1ed9 d\u00e0i \u0111\u01b0\u1ee3c khai b\u00e1o (d\u00f9 chu\u1ed7i ng\u1eafn h\u01a1n).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ed1n dung l\u01b0\u1ee3ng \u0111\u00fang b\u1eb1ng \u0111\u1ed9 d\u00e0i chu\u1ed7i th\u1ef1c t\u1ebf + 1 byte \u0111\u1ec3 l\u01b0u \u0111\u1ed9 d\u00e0i.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hi\u1ec7u su\u1ea5t<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Truy xu\u1ea5t nhanh h\u01a1n v\u00ec \u0111\u1ed9 d\u00e0i c\u1ed1 \u0111\u1ecbnh, kh\u00f4ng c\u1ea7n x\u1eed l\u00fd th\u00eam.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Truy xu\u1ea5t ch\u1eadm h\u01a1n v\u00ec c\u1ea7n x\u1eed l\u00fd \u0111\u1ed9 d\u00e0i chu\u1ed7i th\u1ef1c t\u1ebf.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng ph\u00f9 h\u1ee3p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u c\u00f3 \u0111\u1ed9 d\u00e0i c\u1ed1 \u0111\u1ecbnh ho\u1eb7c g\u1ea7n c\u1ed1 \u0111\u1ecbnh (m\u00e3 PIN, m\u00e3 s\u1ea3n ph\u1ea9m\u2026).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u c\u00f3 \u0111\u1ed9 d\u00e0i thay \u0111\u1ed5i (t\u00ean, m\u00f4 t\u1ea3, \u0111\u1ecba ch\u1ec9\u2026).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Gi\u1edbi h\u1ea1n k\u00edch th\u01b0\u1edbc<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ed1i \u0111a 255 k\u00fd t\u1ef1.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ed1i \u0111a 65,535 k\u00fd t\u1ef1 (t\u00f9y thu\u1ed9c v\u00e0o k\u00edch th\u01b0\u1edbc c\u1ee7a h\u00e0ng v\u00e0 b\u1ea3ng).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u0110\u1ec7m kho\u1ea3ng tr\u1eafng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ef1 \u0111\u1ed9ng \u0111\u1ec7m kho\u1ea3ng tr\u1eafng n\u1ebfu chu\u1ed7i ng\u1eafn h\u01a1n \u0111\u1ed9 d\u00e0i khai b\u00e1o.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng \u0111\u1ec7m kho\u1ea3ng tr\u1eafng, l\u01b0u \u0111\u00fang d\u1eef li\u1ec7u th\u1ef1c t\u1ebf.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Ph\u00e2n bi\u1ec7t FLOAT v\u00e0 DOUBLE nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">FLOAT v\u00e0 DOUBLE l\u00e0 hai ki\u1ec3u d\u1eef li\u1ec7u d\u00f9ng \u0111\u1ec3 l\u01b0u tr\u1eef gi\u00e1 tr\u1ecb s\u1ed1 th\u1ef1c trong c\u00e1c h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u, tuy nhi\u00ean ch\u00fang c\u00f3 s\u1ef1 kh\u00e1c bi\u1ec7t v\u1ec1 \u0111\u1ed9 ch\u00ednh x\u00e1c v\u00e0 dung l\u01b0\u1ee3ng l\u01b0u tr\u1eef.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 b\u1ea3ng so s\u00e1nh chi ti\u1ebft:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>FLOAT<\/b><\/td>\n<td><b>DOUBLE<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u0110\u1ed9 ch\u00ednh x\u00e1c<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ed9 ch\u00ednh x\u00e1c \u0111\u01a1n (single precision), kho\u1ea3ng 7 ch\u1eef s\u1ed1 th\u1eadp ph\u00e2n.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ed9 ch\u00ednh x\u00e1c k\u00e9p (double precision), kho\u1ea3ng 15 ch\u1eef s\u1ed1 th\u1eadp ph\u00e2n.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Dung l\u01b0\u1ee3ng l\u01b0u tr\u1eef<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ed1n 4 byte (32-bit).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ed1n 8 byte (64-bit).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Ph\u1ea1m vi gi\u00e1 tr\u1ecb<\/span><\/td>\n<td><span style=\"font-weight: 400;\">R\u1ed9ng h\u01a1n <\/span><span style=\"font-weight: 400;\">INTEGER<\/span><span style=\"font-weight: 400;\"> nh\u01b0ng nh\u1ecf h\u01a1n <\/span><span style=\"font-weight: 400;\">DOUBLE.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u1ea1m vi gi\u00e1 tr\u1ecb l\u1edbn h\u01a1n, th\u00edch h\u1ee3p cho s\u1ed1 r\u1ea5t l\u1edbn ho\u1eb7c r\u1ea5t nh\u1ecf.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hi\u1ec7u su\u1ea5t<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Nhanh h\u01a1n do t\u1ed1n \u00edt b\u1ed9 nh\u1edb h\u01a1n.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1eadm h\u01a1n m\u1ed9t ch\u00fat v\u00ec t\u1ed1n nhi\u1ec1u b\u1ed9 nh\u1edb h\u01a1n.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng ph\u00f9 h\u1ee3p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u00f9ng trong c\u00e1c t\u00ednh to\u00e1n kh\u00f4ng y\u00eau c\u1ea7u \u0111\u1ed9 ch\u00ednh x\u00e1c cao (v\u00ed d\u1ee5: game, \u0111\u1ed3 h\u1ecda).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u00f9ng trong c\u00e1c t\u00ednh to\u00e1n c\u1ea7n \u0111\u1ed9 ch\u00ednh x\u00e1c cao (v\u00ed d\u1ee5: khoa h\u1ecdc, t\u00e0i ch\u00ednh).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u01b0u gi\u00e1 tr\u1ecb nh\u01b0 <\/span><span style=\"font-weight: 400;\">12345.67<\/span><span style=\"font-weight: 400;\"> (c\u00f3 th\u1ec3 b\u1ecb l\u00e0m tr\u00f2n).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u01b0u ch\u00ednh x\u00e1c gi\u00e1 tr\u1ecb nh\u01b0 <\/span><span style=\"font-weight: 400;\">12345.6789012345.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Ph\u00e2n bi\u1ec7t LENGTH v\u00e0 CHAR_LENGTH nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">LENGTH v\u00e0 CHAR_LENGTH l\u00e0 hai h\u00e0m trong SQL d\u00f9ng \u0111\u1ec3 t\u00ednh \u0111\u1ed9 d\u00e0i c\u1ee7a chu\u1ed7i. D\u00f9 c\u00f3 v\u1ebb gi\u1ed1ng nhau, nh\u01b0ng ch\u00fang l\u1ea1i ho\u1ea1t \u0111\u1ed9ng kh\u00e1c nhau trong vi\u1ec7c \u0111o l\u01b0\u1eddng v\u00e0 x\u1eed l\u00fd k\u00fd t\u1ef1.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 b\u1ea3ng so s\u00e1nh gi\u00fap l\u00e0m r\u00f5 2 ki\u1ec3u d\u1eef li\u1ec7u n\u00e0y:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>LENGTH<\/b><\/td>\n<td><b>CHAR_LENGTH<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Ch\u1ee9c n\u0103ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u00ednh t\u1ed5ng s\u1ed1 byte c\u1ee7a chu\u1ed7i.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u00ednh t\u1ed5ng s\u1ed1 k\u00fd t\u1ef1 trong chu\u1ed7i.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u0110\u01a1n v\u1ecb \u0111o l\u01b0\u1eddng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1ed1 byte (t\u00f9y thu\u1ed9c v\u00e0o encoding, m\u1ed9t k\u00fd t\u1ef1 c\u00f3 th\u1ec3 chi\u1ebfm nhi\u1ec1u byte).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1ed1 k\u00fd t\u1ef1 (m\u1ed7i k\u00fd t\u1ef1 \u0111\u01b0\u1ee3c t\u00ednh l\u00e0 m\u1ed9t \u0111\u01a1n v\u1ecb, b\u1ea5t k\u1ec3 encoding).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 ki\u1ec3m tra k\u00edch th\u01b0\u1edbc chu\u1ed7i khi l\u01b0u tr\u1eef trong c\u01a1 s\u1edf d\u1eef li\u1ec7u, \u0111\u1eb7c bi\u1ec7t khi l\u00e0m vi\u1ec7c v\u1edbi c\u00e1c encoding ph\u1ee9c t\u1ea1p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u00edch h\u1ee3p khi x\u1eed l\u00fd chu\u1ed7i text \u1edf m\u1ee9c k\u00fd t\u1ef1 logic, ch\u1eb3ng h\u1ea1n ki\u1ec3m tra \u0111\u1ed9 d\u00e0i t\u00ean ng\u01b0\u1eddi d\u00f9ng<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Encoding \u1ea3nh h\u01b0\u1edfng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3, c\u00e1c k\u00fd t\u1ef1 Unicode ho\u1eb7c multi-byte s\u1ebd l\u00e0m t\u0103ng k\u1ebft qu\u1ea3 LENGTH.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng, lu\u00f4n \u0111\u1ebfm theo s\u1ed1 k\u00fd t\u1ef1, kh\u00f4ng ph\u1ee5 thu\u1ed9c v\u00e0o encoding.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">LENGTH(&#8216;A&#8217;) = 1, LENGTH(&#8216;\u00c1&#8217;) = 2<\/span><span style=\"font-weight: 400;\"> (v\u1edbi UTF-8 encoding).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">CHAR_LENGTH(&#8216;A&#8217;) = 1, CHAR_LENGTH(&#8216;\u00c1&#8217;) = 1.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Ph\u00e2n bi\u1ec7t NOW() v\u00e0 CURRENT_DATE() nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">NOW() v\u00e0 CURRENT_DATE() l\u00e0 hai h\u00e0m th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong SQL \u0111\u1ec3 l\u00e0m vi\u1ec7c v\u1edbi d\u1eef li\u1ec7u th\u1eddi gian. M\u1eb7c d\u00f9 c\u1ea3 hai \u0111\u1ec1u li\u00ean quan \u0111\u1ebfn th\u1eddi gian, nh\u01b0ng ch\u00fang c\u00f3 m\u1ee5c \u0111\u00edch v\u00e0 c\u00e1ch tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 kh\u00e1c nhau.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 b\u1ea3ng so s\u00e1nh chi ti\u1ebft:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>NOW()<\/b><\/td>\n<td><b>CURRENT_DATE()<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Ch\u1ee9c n\u0103ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 ng\u00e0y v\u00e0 gi\u1edd hi\u1ec7n t\u1ea1i.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 ng\u00e0y hi\u1ec7n t\u1ea1i, kh\u00f4ng bao g\u1ed3m gi\u1edd.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u0110\u1ecbnh d\u1ea1ng tr\u1ea3 v\u1ec1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">YYYY-MM-DD HH:MM:SS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">YYYY-MM-DD<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u tr\u1ea3 v\u1ec1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Bao g\u1ed3m c\u1ea3 ng\u00e0y v\u00e0 th\u1eddi gian c\u1ee5 th\u1ec3.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1ec9 tr\u1ea3 v\u1ec1 ph\u1ea7n ng\u00e0y (kh\u00f4ng c\u00f3 th\u1eddi gian).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng ph\u00f9 h\u1ee3p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng khi c\u1ea7n c\u1ea3 ng\u00e0y v\u00e0 gi\u1edd (v\u00ed d\u1ee5: timestamp).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng khi ch\u1ec9 c\u1ea7n ng\u00e0y (v\u00ed d\u1ee5: l\u01b0u ng\u00e0y sinh).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2024-12-14 15:30:45<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2024-12-14<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa SQL v\u00e0 MySQL l\u00e0 g\u00ec?<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>SQL<\/b><\/td>\n<td><b>MySQL<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u0110\u1ecbnh ngh\u0129a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0 ng\u00f4n ng\u1eef truy v\u1ea5n c\u01a1 s\u1edf d\u1eef li\u1ec7u chu\u1ea9n<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0 m\u1ed9t h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u &#8211; s\u1eed d\u1ee5ng SQL \u0111\u1ec3 x\u1eed l\u00fd d\u1eef li\u1ec7u<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">M\u1ee5c \u0111\u00edch<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 giao ti\u1ebfp v\u1edbi c\u01a1 s\u1edf d\u1eef li\u1ec7u: truy v\u1ea5n, c\u1eadp nh\u1eadt, x\u00f3a ho\u1eb7c ch\u1ec9nh s\u1eeda d\u1eef li\u1ec7u.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 qu\u1ea3n l\u00fd c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 cung c\u1ea5p kh\u1ea3 n\u0103ng th\u1ef1c thi c\u00e1c c\u00e2u l\u1ec7nh SQL.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Ph\u00e2n lo\u1ea1i<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0 m\u1ed9t ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh chu\u1ea9n, kh\u00f4ng ph\u1ee5 thu\u1ed9c v\u00e0o h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u n\u00e0o.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0 m\u1ed9t ph\u1ea7n m\u1ec1m c\u1ee5 th\u1ec3, d\u1ef1a tr\u00ean SQL, thu\u1ed9c s\u1edf h\u1eefu c\u1ee7a Oracle Corporation.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">T\u00ednh n\u0103ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Quy \u0111\u1ecbnh ng\u00f4n ng\u1eef chu\u1ea9n \u0111\u1ec3 thao t\u00e1c v\u1edbi c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Cung c\u1ea5p c\u00f4ng c\u1ee5 v\u00e0 m\u00f4i tr\u01b0\u1eddng \u0111\u1ec3 qu\u1ea3n l\u00fd c\u01a1 s\u1edf d\u1eef li\u1ec7u m\u1ed9t c\u00e1ch hi\u1ec7u qu\u1ea3.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">T\u00ednh linh ho\u1ea1t<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u01b0\u1ee3c s\u1eed d\u1ee5ng b\u1edfi nhi\u1ec1u h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u (MySQL, PostgreSQL, SQL Server).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1ec9 ho\u1ea1t \u0111\u1ed9ng trong khung h\u1ec7 th\u1ed1ng c\u1ee7a ri\u00eang n\u00f3.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00f4ng ty qu\u1ea3n l\u00fd<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng thu\u1ed9c quy\u1ec1n qu\u1ea3n l\u00fd c\u1ee7a b\u1ea5t k\u1ef3 c\u00f4ng ty n\u00e0o.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Thu\u1ed9c quy\u1ec1n qu\u1ea3n l\u00fd c\u1ee7a Oracle Corporation.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>C\u00e1c l\u1ec7nh c\u01a1 b\u1ea3n trong MySQL v\u00e0 v\u00ed d\u1ee5 c\u1ee5 th\u1ec3<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">MySQL l\u00e0 m\u1ed9t h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u ph\u1ed5 bi\u1ebfn, cung c\u1ea5p nhi\u1ec1u l\u1ec7nh h\u1eefu \u00edch \u0111\u1ec3 thao t\u00e1c v\u1edbi d\u1eef li\u1ec7u. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 m\u1ed9t s\u1ed1 l\u1ec7nh c\u01a1 b\u1ea3n v\u00e0 c\u00e1ch s\u1eed d\u1ee5ng ch\u00fang:<\/span><\/p>\n<h4><strong>L\u1ec7nh SELECT<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 truy v\u1ea5n d\u1eef li\u1ec7u t\u1eeb m\u1ed9t ho\u1eb7c nhi\u1ec1u b\u1ea3ng, th\u01b0\u1eddng k\u1ebft h\u1ee3p v\u1edbi \u0111i\u1ec1u ki\u1ec7n <\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 l\u1ecdc d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:\u00a0<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT column1, column2, ...\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM table_name\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE condition;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 l\u1ea5y danh s\u00e1ch t\u00ean v\u00e0 tu\u1ed5i c\u1ee7a ng\u01b0\u1eddi d\u00f9ng t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT name, age\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM employees\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE age &gt; 18;<\/span><\/pre>\n<h4><strong>L\u1ec7nh INSERT<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 th\u00eam m\u1ed9t ho\u1eb7c nhi\u1ec1u b\u1ea3n ghi m\u1edbi v\u00e0o b\u1ea3ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO table_name (column1, column2, ...)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (value1, value2, ...);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 th\u00eam d\u1eef li\u1ec7u m\u1ed9t ng\u01b0\u1eddi d\u00f9ng m\u1edbi v\u00e0o b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO employees (id, name, age)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (1, 'John Doe', 28);<\/span><\/pre>\n<p><strong>L\u1ec7nh UPDATE<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 c\u1eadp nh\u1eadt d\u1eef li\u1ec7u trong b\u1ea3ng, d\u1ef1a tr\u00ean \u0111i\u1ec1u ki\u1ec7n trong c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">UPDATE table_name\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">SET column1 = value1, column2 = value2, ...\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE condition;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 c\u1eadp nh\u1eadt tu\u1ed5i c\u1ee7a nh\u00e2n vi\u00ean c\u00f3 ID l\u00e0 1 th\u00e0nh 29 ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">UPDATE employees\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">SET age = 29\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE id = 1;<\/span><\/pre>\n<h4><strong>L\u1ec7nh DELETE<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 x\u00f3a m\u1ed9t ho\u1eb7c nhi\u1ec1u b\u1ea3n ghi t\u1eeb b\u1ea3ng, d\u1ef1a tr\u00ean \u0111i\u1ec1u ki\u1ec7n \u0111\u01b0\u1ee3c cung c\u1ea5p.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM table_name WHERE condition;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 x\u00f3a th\u00f4ng tin t\u1ea5t c\u1ea3 nh\u00e2n vi\u00ean c\u00f3 \u0111\u1ed9 tu\u1ed5i nh\u1ecf h\u01a1n 25 kh\u1ecfi b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\">, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM employees WHERE age &lt; 25;<\/span><\/pre>\n<p><strong>L\u1ec7nh CREATE TABLE<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 t\u1ea1o m\u1ed9t b\u1ea3ng m\u1edbi.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TABLE table_name (\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0column1 datatype,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0column2 datatype, ...\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u1ea1o b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">users<\/span><\/i><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TABLE users (<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0id INT PRIMARY KEY,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0name VARCHAR(100),<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0age INT\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<h4><strong>L\u1ec7nh DROP TABLE<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 x\u00f3a b\u1ea3ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DROP TABLE &lt;table_name&gt;;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 x\u00f3a b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">users<\/span><\/i><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DROP TABLE users;<\/span><\/pre>\n<h4><strong>L\u1ec7nh ALTER<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 thay \u0111\u1ed5i c\u1ea5u tr\u00fac c\u1ee7a b\u1ea3ng, v\u00ed d\u1ee5 nh\u01b0 th\u00eam ho\u1eb7c x\u00f3a c\u1ed9t.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\u2013- \u0110\u1ec3 th\u00eam c\u1ed9t m\u1edbi v\u00e0o b\u1ea3ng<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ALTER TABLE table_name ADD column_name datatype;\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u2013- \u0110\u1ec3 xo\u00e1 c\u1ed9t kh\u1ecfi b\u1ea3ng<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ALTER TABLE table_name DROP column_name;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 h\u00eam m\u1ed9t c\u1ed9t m\u1edbi c\u00f3 t\u00ean <\/span><i><span style=\"font-weight: 400;\">address<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0o b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\">, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">ALTER TABLE employees ADD address VARCHAR(255);<\/span><\/pre>\n<h3><b>Import database trong MySQL nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Import database trong MySQL l\u00e0 vi\u1ec7c n\u1ea1p d\u1eef li\u1ec7u t\u1eeb m\u1ed9t file sao l\u01b0u (th\u01b0\u1eddng l\u00e0 <\/span><span style=\"font-weight: 400;\">.sql<\/span><span style=\"font-weight: 400;\">) v\u00e0o h\u1ec7 th\u1ed1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u. C\u00f3 3 c\u00e1ch th\u1ef1c hi\u1ec7n import d\u1eef li\u1ec7u nh\u01b0 sau:<\/span><\/p>\n<h4><b>C\u00e1ch 1: Import b\u1eb1ng Command Line<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">L\u00e0 c\u00e1ch ph\u1ed5 bi\u1ebfn nh\u1ea5t, ph\u00f9 h\u1ee3p v\u1edbi nh\u1eefng ng\u01b0\u1eddi quen l\u00e0m vi\u1ec7c tr\u00ean giao di\u1ec7n d\u00f2ng l\u1ec7nh, \u0111\u1eb7c bi\u1ec7t tr\u00ean h\u1ec7 th\u1ed1ng Linux ho\u1eb7c m\u00e1y ch\u1ee7.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1ch th\u1ef1c hi\u1ec7n:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>B\u01b0\u1edbc 1:<\/strong> \u0110\u1ea3m b\u1ea3o file <\/span><span style=\"font-weight: 400;\">.sql<\/span><span style=\"font-weight: 400;\"> c\u1ea7n import \u0111\u00e3 s\u1eb5n s\u00e0ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>B\u01b0\u1edbc 2:<\/strong> Ki\u1ec3m tra v\u00e0 \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u00edch \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ea1o. Trong tr\u01b0\u1eddng h\u1ee3p database ch\u01b0a \u0111\u01b0\u1ee3c t\u1ea1o, ta c\u00f3 th\u1ec3 d\u00f9ng c\u00e2u l\u1ec7nh sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE DATABASE database_name;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\"><strong>B\u01b0\u1edbc 3:<\/strong> M\u1edf Command Line (Terminal) tr\u00ean m\u00e1y t\u00ednh. <\/span><span style=\"font-weight: 400;\">Nh\u1eadp l\u1ec7nh sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">mysql -u username -p database_name &lt; path\/to\/file.sql<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">username<\/span><span style=\"font-weight: 400;\">: T\u00ean ng\u01b0\u1eddi d\u00f9ng MySQL (th\u01b0\u1eddng l\u00e0 <\/span><span style=\"font-weight: 400;\">root<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">database_name<\/span><span style=\"font-weight: 400;\">: T\u00ean c\u01a1 s\u1edf d\u1eef li\u1ec7u m\u00e0 b\u1ea1n mu\u1ed1n import.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">path\/to\/file.sql<\/span><span style=\"font-weight: 400;\">: \u0110\u01b0\u1eddng d\u1eabn \u0111\u1ebfn file <\/span><span style=\"font-weight: 400;\">.sql<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n<h4><b>C\u00e1ch 2: Import b\u1eb1ng MySQL Workbench (Ho\u1eb7c c\u00e1c MySQL Database Management Tools kh\u00e1c)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">MySQL Workbench l\u00e0 c\u00f4ng c\u1ee5 giao di\u1ec7n \u0111\u1ed3 h\u1ecda, gi\u00fap b\u1ea1n thao t\u00e1c tr\u1ef1c quan v\u1edbi MySQL. C\u00e1ch n\u00e0y ph\u00f9 h\u1ee3p v\u1edbi nh\u1eefng ng\u01b0\u1eddi d\u00f9ng kh\u00f4ng quen d\u00f9ng l\u1ec7nh ho\u1eb7c c\u1ea7n giao di\u1ec7n tr\u1ef1c quan.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1c b\u01b0\u1edbc th\u1ef1c hi\u1ec7n:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">M\u1edf MySQL Workbench v\u00e0 k\u1ebft n\u1ed1i \u0111\u1ebfn m\u00e1y ch\u1ee7 MySQL.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">T\u1ea1o m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u m\u1edbi ho\u1eb7c ch\u1ecdn c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u00f3 s\u1eb5n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">V\u00e0o menu <\/span><b>Server &gt; Data Import<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ch\u1ecdn t\u00f9y ch\u1ecdn <\/span><b>Import from Self-Contained File<\/b><span style=\"font-weight: 400;\"> v\u00e0 t\u00ecm \u0111\u1ebfn file <\/span><span style=\"font-weight: 400;\">.sql<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Trong m\u1ee5c <\/span><b>Default Schema to be Imported To<\/b><span style=\"font-weight: 400;\">, ch\u1ecdn c\u01a1 s\u1edf d\u1eef li\u1ec7u m\u1ee5c ti\u00eau.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Nh\u1ea5n <\/span><b>Start Import<\/b><span style=\"font-weight: 400;\"> \u0111\u1ec3 b\u1eaft \u0111\u1ea7u qu\u00e1 tr\u00ecnh.<\/span><\/li>\n<\/ol>\n<h4><b>C\u00e1ch 3: Import b\u1eb1ng phpMyAdmin<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">phpMyAdmin l\u00e0 c\u00f4ng c\u1ee5 qu\u1ea3n l\u00fd MySQL th\u00f4ng qua giao di\u1ec7n web, th\u01b0\u1eddng \u0111\u01b0\u1ee3c d\u00f9ng tr\u00ean c\u00e1c m\u00e1y ch\u1ee7 c\u00e0i s\u1eb5n (nh\u01b0 XAMPP, LAMP).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1ch th\u1ef1c hi\u1ec7n:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u0103ng nh\u1eadp v\u00e0o phpMyAdmin qua tr\u00ecnh duy\u1ec7t web.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ch\u1ecdn c\u01a1 s\u1edf d\u1eef li\u1ec7u m\u00e0 b\u1ea1n mu\u1ed1n import d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Nh\u1ea5n v\u00e0o tab <\/span><b>Import<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">B\u1ea5m <\/span><b>Choose File<\/b><span style=\"font-weight: 400;\"> \u0111\u1ec3 ch\u1ecdn file <\/span><span style=\"font-weight: 400;\">.sql<\/span><span style=\"font-weight: 400;\"> t\u1eeb m\u00e1y t\u00ednh c\u1ee7a b\u1ea1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Nh\u1ea5n <\/span><b>Go<\/b><span style=\"font-weight: 400;\"> \u0111\u1ec3 b\u1eaft \u0111\u1ea7u import.<\/span><\/li>\n<\/ol>\n<h3><b>MySQL c\u00f3 bao nhi\u00eau lo\u1ea1i storage engine?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">MySQL h\u1ed7 tr\u1ee3 nhi\u1ec1u lo\u1ea1i Storage Engine kh\u00e1c nhau, m\u1ed7i lo\u1ea1i cung c\u1ea5p c\u00e1c c\u00e1ch l\u01b0u tr\u1eef, truy xu\u1ea5t v\u00e0 qu\u1ea3n l\u00fd d\u1eef li\u1ec7u ph\u00f9 h\u1ee3p v\u1edbi nh\u1eefng nhu c\u1ea7u c\u1ee5 th\u1ec3. Hi\u1ec7n t\u1ea1i, MySQL t\u00edch h\u1ee3p s\u1eb5n c\u00e1c Storage Engine ch\u00ednh v\u00e0 c\u0169ng cho ph\u00e9p b\u1ed5 sung c\u00e1c lo\u1ea1i engine b\u00ean ngo\u00e0i t\u00f9y theo \u1ee9ng d\u1ee5ng.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Storage Engine<\/b><\/td>\n<td><b>\u0110\u1eb7c \u0111i\u1ec3m ch\u00ednh<\/b><\/td>\n<td><b>\u1ee8ng d\u1ee5ng ph\u1ed5 bi\u1ebfn<\/b><\/td>\n<td><b>H\u1ea1n ch\u1ebf<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">InnoDB (m\u1eb7c \u0111\u1ecbnh)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 giao d\u1ecbch (transactions), t\u00ednh n\u0103ng ACID.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u00f3a c\u1ea5p h\u00e0ng (row-level locking).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 kh\u00f3a ngo\u1ea1i (foreign key constraints).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00e1c \u1ee9ng d\u1ee5ng y\u00eau c\u1ea7u t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u cao nh\u01b0 ng\u00e2n h\u00e0ng, th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Hi\u1ec7u su\u1ea5t ghi th\u1ea5p h\u01a1n MyISAM trong c\u00e1c t\u00e1c v\u1ee5 \u0111\u01a1n gi\u1ea3n.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Ti\u00eau th\u1ee5 nhi\u1ec1u t\u00e0i nguy\u00ean h\u1ec7 th\u1ed1ng h\u01a1n.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">MyISAM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; T\u1ed1i \u01b0u cho t\u1ed1c \u0111\u1ed9 \u0111\u1ecdc.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 kh\u00f3a c\u1ea5p b\u1ea3ng (table-level locking).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Ti\u1ebft ki\u1ec7m t\u00e0i nguy\u00ean h\u01a1n InnoDB.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; \u1ee8ng d\u1ee5ng ch\u1ec9 \u0111\u1ecdc (read-heavy), nh\u01b0 CMS ho\u1eb7c blog.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Ph\u00e2n t\u00edch d\u1eef li\u1ec7u.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Kh\u00f4ng h\u1ed7 tr\u1ee3 giao d\u1ecbch ho\u1eb7c kh\u00f3a ngo\u1ea1i.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; D\u1eef li\u1ec7u c\u00f3 th\u1ec3 b\u1ecb m\u1ea5t trong tr\u01b0\u1eddng h\u1ee3p t\u1eaft m\u00e1y \u0111\u1ed9t ng\u1ed9t.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">MEMORY<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; L\u01b0u tr\u1eef d\u1eef li\u1ec7u trong RAM, t\u1ed1c \u0111\u1ed9 truy c\u1eadp c\u1ef1c nhanh.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u00f3a c\u1ea5p b\u1ea3ng (table-level locking).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; B\u1ea3ng t\u1ea1m th\u1eddi.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; D\u1eef li\u1ec7u c\u1ea7n truy c\u1eadp nhanh trong th\u1eddi gian ng\u1eafn.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; D\u1eef li\u1ec7u b\u1ecb m\u1ea5t khi t\u1eaft ho\u1eb7c kh\u1edfi \u0111\u1ed9ng l\u1ea1i m\u00e1y ch\u1ee7.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u00f4ng h\u1ed7 tr\u1ee3 d\u1eef li\u1ec7u l\u1edbn ho\u1eb7c giao d\u1ecbch.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CSV<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; L\u01b0u d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng file CSV (Comma-Separated Values).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; D\u1ec5 d\u00e0ng trao \u0111\u1ed5i d\u1eef li\u1ec7u v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng kh\u00e1c<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Xu\u1ea5t\/nh\u1eadp d\u1eef li\u1ec7u v\u1edbi ph\u1ea7n m\u1ec1m b\u00ean ngo\u00e0i nh\u01b0 Excel.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng h\u1ed7 tr\u1ee3 c\u00e1c t\u00ednh n\u0103ng n\u00e2ng cao nh\u01b0 giao d\u1ecbch, ch\u1ec9 m\u1ee5c, ho\u1eb7c kh\u00f3a.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ARCHIVE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; N\u00e9n d\u1eef li\u1ec7u \u0111\u1ec3 ti\u1ebft ki\u1ec7m kh\u00f4ng gian.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Ch\u1ec9 h\u1ed7 tr\u1ee3 <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\">.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u01b0u tr\u1eef log, d\u1eef li\u1ec7u th\u1ed1ng k\u00ea, ho\u1eb7c l\u1ecbch s\u1eed giao d\u1ecbch.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng h\u1ed7 tr\u1ee3 c\u1eadp nh\u1eadt (<\/span><span style=\"font-weight: 400;\">UPDATE<\/span><span style=\"font-weight: 400;\">) ho\u1eb7c x\u00f3a (<\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\">) d\u1eef li\u1ec7u.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">BLACKHOLE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng l\u01b0u d\u1eef li\u1ec7u, m\u1ecdi thao t\u00e1c ghi d\u1eef li\u1ec7u b\u1ecb b\u1ecf qua.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ki\u1ec3m tra ho\u1eb7c ghi log \u0111\u1eb7c bi\u1ec7t.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng l\u01b0u d\u1eef li\u1ec7u th\u1ef1c t\u1ebf, ch\u1ec9 d\u00f9ng trong c\u00e1c tr\u01b0\u1eddng h\u1ee3p \u0111\u1eb7c bi\u1ec7t nh\u01b0 ki\u1ec3m th\u1eed.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">NDB (Clustered)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; L\u01b0u tr\u1eef d\u1eef li\u1ec7u ph\u00e2n t\u00e1n tr\u00ean nhi\u1ec1u m\u00e1y ch\u1ee7 (MySQL Cluster).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Hi\u1ec7u su\u1ea5t cao, \u0111\u1ed9 tr\u1ec5 th\u1ea5p.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng theo chi\u1ec1u ngang<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; H\u1ec7 th\u1ed1ng ph\u00e2n t\u00e1n y\u00eau c\u1ea7u t\u00ednh s\u1eb5n s\u00e0ng cao.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; X\u1eed l\u00fd d\u1eef li\u1ec7u th\u1eddi gian th\u1ef1c.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Y\u00eau c\u1ea7u c\u1ea5u h\u00ecnh ph\u1ee9c t\u1ea1p v\u00e0 t\u00e0i nguy\u00ean l\u1edbn.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">FEDERATED<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; K\u1ebft n\u1ed1i t\u1edbi c\u01a1 s\u1edf d\u1eef li\u1ec7u t\u1eeb xa, kh\u00f4ng l\u01b0u d\u1eef li\u1ec7u c\u1ee5c b\u1ed9.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Ch\u1ec9 l\u01b0u tr\u1eef c\u1ea5u tr\u00fac b\u1ea3ng (schema), c\u00f2n d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c truy v\u1ea5n t\u1eeb m\u00e1y ch\u1ee7 t\u1eeb xa<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Truy c\u1eadp c\u01a1 s\u1edf d\u1eef li\u1ec7u tr\u00ean m\u00e1y ch\u1ee7 kh\u00e1c m\u00e0 kh\u00f4ng c\u1ea7n sao ch\u00e9p.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Hi\u1ec7u su\u1ea5t ph\u1ee5 thu\u1ed9c v\u00e0o m\u1ea1ng v\u00e0 m\u00e1y ch\u1ee7 t\u1eeb xa.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u1ea3 n\u0103ng qu\u1ea3n l\u00fd h\u1ea1n ch\u1ebf.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u00f4ng h\u1ed7 tr\u1ee3 giao d\u1ecbch, kh\u00f3a ngo\u1ea1i hay ch\u1ec9 m\u1ee5c<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TokuDB<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; S\u1eed d\u1ee5ng c\u1ea5u tr\u00fac l\u01b0u tr\u1eef \u0111\u1eb7c bi\u1ec7t, g\u1ecdi l\u00e0 Fractal Tree Indexes<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; T\u1ed1i \u01b0u l\u01b0u tr\u1eef d\u1eef li\u1ec7u l\u1edbn v\u1edbi kh\u1ea3 n\u0103ng n\u00e9n cao.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 giao d\u1ecbch v\u00e0 ACID nh\u01b0 InnoDB.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u00f3a c\u1ea5p d\u00f2ng, sao l\u01b0u d\u1eef li\u1ec7u kh\u00f4ng g\u00e2y gi\u00e1n \u0111o\u1ea1n \u1ee9ng d\u1ee5ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; H\u1ec7 th\u1ed1ng Big Data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; C\u00e1c \u1ee9ng d\u1ee5ng y\u00eau c\u1ea7u x\u1eed l\u00fd l\u01b0\u1ee3ng d\u1eef li\u1ec7u kh\u1ed5ng l\u1ed3.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Y\u00eau c\u1ea7u t\u00e0i nguy\u00ean l\u1edbn.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; \u00cdt ph\u1ed5 bi\u1ebfn so v\u1edbi c\u00e1c engine kh\u00e1c.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>C\u00e1c quy t\u1eafc c\u01a1 b\u1ea3n c\u1ee7a REGEXP l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">REGEXP (vi\u1ebft t\u1eaft c\u1ee7a Regular Expression) l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p quy t\u1eafc ho\u1eb7c m\u1eabu (patterns) \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 kh\u1edbp (match) ho\u1eb7c t\u00ecm ki\u1ebfm c\u00e1c chu\u1ed7i c\u1ee5 th\u1ec3 trong v\u0103n b\u1ea3n th\u00f4ng qua bi\u1ec3u th\u1ee9c ch\u00ednh quy. N\u00f3 gi\u1ed1ng nh\u01b0 m\u1ed9t \u201cng\u00f4n ng\u1eef mini\u201d gi\u00fap \u0111\u1ecbnh ngh\u0129a c\u00e1c quy t\u1eafc \u0111\u1ec3 x\u1eed l\u00fd chu\u1ed7i.<\/span><\/p>\n<h4><b>K\u00fd t\u1ef1 th\u01b0\u1eddng<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">C\u00e1c k\u00fd t\u1ef1 nh\u01b0 <\/span><span style=\"font-weight: 400;\">a,b,c<\/span><span style=\"font-weight: 400;\"> s\u1ebd so kh\u1edbp ch\u00ednh x\u00e1c v\u1edbi ch\u00fang trong chu\u1ed7i.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: M\u1eabu <\/span><span style=\"font-weight: 400;\">abc<\/span><span style=\"font-weight: 400;\"> s\u1ebd t\u00ecm th\u1ea5y t\u1eeb \u201cabc\u201d trong chu\u1ed7i \u201cabc123\u201d.<\/span><\/p>\n<h4><b>K\u00fd t\u1ef1 \u0111\u1eb7c bi\u1ec7t<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">REGEXP c\u00f3 c\u00e1c k\u00fd hi\u1ec7u \u0111\u1eb7c bi\u1ec7t gi\u00fap m\u1edf r\u1ed9ng kh\u1ea3 n\u0103ng t\u00ecm ki\u1ebfm \u0111\u01b0\u1ee3c quy \u0111\u1ecbnh nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">K\u00fd t\u1ef1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u00dd ngh\u0129a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ea1i di\u1ec7n cho b\u1ea5t k\u1ef3 k\u00fd t\u1ef1 n\u00e0o<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1eabu a.c s\u1ebd kh\u1edbp v\u1edbi \u201cabc\u201d, \u201ca1c\u201d, \u201ca-c\u201d<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">*<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u1eb7p l\u1ea1i k\u00fd t\u1ef1 \u0111\u1ee9ng tr\u01b0\u1edbc 0 ho\u1eb7c nhi\u1ec1u l\u1ea7n<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1eabu ab* s\u1ebd kh\u1edbp v\u1edbi \u201ca\u201d, \u201cab\u201d, \u201cabb\u201d, \u201cabbb\u201d<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">+<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u1eb7p l\u1ea1i k\u00fd t\u1ef1 \u0111\u1ee9ng tr\u01b0\u1edbc \u00edt nh\u1ea5t 1 l\u1ea7n<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1eabu ab+ s\u1ebd kh\u1edbp v\u1edbi \u201cab\u201d, \u201cabb\u201d, nh\u01b0ng kh\u00f4ng kh\u1edbp v\u1edbi \u201ca\u201d<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">?<\/span><\/td>\n<td><span style=\"font-weight: 400;\">K\u00fd t\u1ef1 tr\u01b0\u1edbc n\u00f3 c\u00f3 th\u1ec3 xu\u1ea5t hi\u1ec7n ho\u1eb7c kh\u00f4ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1eabu colou?r s\u1ebd kh\u1edbp v\u1edbi c\u1ea3 \u201ccolor\u201d v\u00e0 \u201ccolour\u201d<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">[]<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ea1i di\u1ec7n cho m\u1ed9t t\u1eadp h\u1ee3p k\u00fd t\u1ef1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1eabu [aeiou] s\u1ebd t\u00ecm th\u1ea5y c\u00e1c nguy\u00ean \u00e2m<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><b>T\u1eadp h\u1ee3p k\u00fd t\u1ef1<\/b><\/h4>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">[abc]<\/span><span style=\"font-weight: 400;\">: M\u1ed9t k\u00fd t\u1ef1 trong danh s\u00e1ch. V\u00ed d\u1ee5 [abc] s\u1ebd kh\u1edbp v\u1edbi \u2018a\u2019<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">[a-z]<\/span><span style=\"font-weight: 400;\">: K\u00fd t\u1ef1 n\u1eb1m trong kho\u1ea3ng a-z. V\u00ed d\u1ee5 [a-z] kh\u1edbp \u201cb\u201d, \u201cx\u201d<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">[^a-z]<\/span><span style=\"font-weight: 400;\">: K\u00fd t\u1ef1 kh\u00f4ng n\u1eb1m trong kho\u1ea3ng a-z. V\u00ed d\u1ee5 [^a-z] kh\u1edbp \u201c1\u201d, \u201c@\u201d<\/span><\/li>\n<\/ul>\n<h4><b>T\u1eadp h\u1ee3p m\u1edf r\u1ed9ng<\/b><\/h4>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\\d<\/span><span style=\"font-weight: 400;\">: \u0110\u1ea1i di\u1ec7n cho ch\u1eef s\u1ed1 (0-9).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\\w<\/span><span style=\"font-weight: 400;\">: \u0110\u1ea1i di\u1ec7n cho ch\u1eef c\u00e1i, ch\u1eef s\u1ed1 v\u00e0 d\u1ea5u g\u1ea1ch d\u01b0\u1edbi (<\/span><span style=\"font-weight: 400;\">[a-zA-Z0-9_]<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\\s<\/span><span style=\"font-weight: 400;\">: \u0110\u1ea1i di\u1ec7n cho kho\u1ea3ng tr\u1eafng (space, tab, newline).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">^:<\/span><span style=\"font-weight: 400;\"> B\u1eaft \u0111\u1ea7u chu\u1ed7i. <\/span>V\u00ed d\u1ee5: M\u1eabu ^abc kh\u1edbp v\u1edbi chu\u1ed7i b\u1eaft \u0111\u1ea7u b\u1eb1ng &#8220;abc&#8221;.<\/li>\n<li><span style=\"font-weight: 400;\">$<\/span><span style=\"font-weight: 400;\">: K\u1ebft th\u00fac chu\u1ed7i. <\/span>V\u00ed d\u1ee5: M\u1eabu xyz$ kh\u1edbp v\u1edbi chu\u1ed7i k\u1ebft th\u00fac b\u1eb1ng &#8220;xyz&#8221;.<\/li>\n<\/ul>\n<h3><b>\u1ee8ng d\u1ee5ng c\u1ee7a REGEXP l\u00e0 g\u00ec?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u00ecm ki\u1ebfm v\u0103n b\u1ea3n:<\/b><span style=\"font-weight: 400;\"> T\u00ecm t\u1ea5t c\u1ea3 email, s\u1ed1 \u0111i\u1ec7n tho\u1ea1i trong m\u1ed9t \u0111o\u1ea1n v\u0103n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ki\u1ec3m tra \u0111\u1ecbnh d\u1ea1ng:<\/b><span style=\"font-weight: 400;\"> X\u00e1c minh \u0111\u1ecbnh d\u1ea1ng email, URL, s\u1ed1 \u0111i\u1ec7n tho\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u00e1ch ho\u1eb7c thay th\u1ebf: <\/b><span style=\"font-weight: 400;\">X\u00f3a k\u00fd t\u1ef1 \u0111\u1eb7c bi\u1ec7t ho\u1eb7c t\u00e1ch chu\u1ed7i d\u1ef1a tr\u00ean d\u1ea5u ph\u00e2n c\u00e1ch.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 n\u1ebfu mu\u1ed1n t\u00ecm t\u1ea5t c\u1ea3 c\u00e1c \u0111\u1ecba ch\u1ec9 email trong m\u1ed9t \u0111o\u1ea1n v\u0103n b\u1ea3n, ta c\u00f3 th\u1ec3 d\u00f9ng m\u1eabu REGEXP trong m\u1ed9t b\u1ea3ng MySQL nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT *\u00a0\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM users\u00a0\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE email REGEXP '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}';<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: M\u1eabu REGEXP <\/span><span style=\"font-weight: 400;\">[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}<\/span><span style=\"font-weight: 400;\"> gi\u00fap t\u00ecm c\u00e1c chu\u1ed7i c\u00f3 \u0111\u1ecbnh d\u1ea1ng email, v\u00ed d\u1ee5: <\/span><span style=\"font-weight: 400;\">example@domain.com<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 n\u1ebfu mu\u1ed1n ki\u1ec3m tra s\u1ed1 \u0111i\u1ec7n tho\u1ea1i Vi\u1ec7t Nam, ta d\u00f9ng m\u1eabu nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT *\u00a0\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM contacts\u00a0\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE phone_number REGEXP '^(\\+84|0)[0-9]{9,10}$';<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: C\u00e2u l\u1ec7nh n\u00e0y t\u00ecm c\u00e1c s\u1ed1 \u0111i\u1ec7n tho\u1ea1i b\u1eaft \u0111\u1ea7u b\u1eb1ng <\/span><span style=\"font-weight: 400;\">+84<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">, ti\u1ebfp theo l\u00e0 9-10 ch\u1eef s\u1ed1. V\u00ed d\u1ee5: <\/span><span style=\"font-weight: 400;\">+84123456789<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">0123456789<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n<h3><strong>L\u1ec7nh JOIN l\u00e0 g\u00ec?<\/strong><\/h3>\n<p><a href=\"https:\/\/itviec.com\/blog\/join-trong-sql\/\" target=\"_blank\" rel=\"noopener\"><strong>L\u1ec7nh JOIN<\/strong><\/a><span style=\"font-weight: 400;\"><strong> trong SQL<\/strong> \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 k\u1ebft h\u1ee3p d\u1eef li\u1ec7u t\u1eeb hai ho\u1eb7c nhi\u1ec1u b\u1ea3ng d\u1ef1a tr\u00ean m\u1ed9t \u0111i\u1ec1u ki\u1ec7n chung. M\u1ed7i lo\u1ea1i <\/span><span style=\"font-weight: 400;\">JOIN<\/span><span style=\"font-weight: 400;\"> ph\u1ee5c v\u1ee5 c\u00e1c m\u1ee5c \u0111\u00edch kh\u00e1c nhau trong vi\u1ec7c x\u1eed l\u00fd d\u1eef li\u1ec7u.<\/span><\/p>\n<h4><b>C\u00fa ph\u00e1p c\u01a1 b\u1ea3n c\u1ee7a l\u1ec7nh <\/b><b>JOIN<\/b><\/h4>\n<pre><span style=\"font-weight: 400;\">SELECT columns\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM table1\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">JOIN_TYPE table2\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON table1.common_column = table2.common_column;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">table1<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">table2<\/span><span style=\"font-weight: 400;\"> l\u00e0 c\u00e1c b\u1ea3ng \u0111\u01b0\u1ee3c tham gia (<\/span><i><span style=\"font-weight: 400;\">join<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">JOIN_TYPE<\/span><span style=\"font-weight: 400;\"> l\u00e0 lo\u1ea1i <\/span><span style=\"font-weight: 400;\">JOIN<\/span><span style=\"font-weight: 400;\"> (INNER, LEFT, RIGHT, FULL).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">ON<\/span><span style=\"font-weight: 400;\"> x\u00e1c \u0111\u1ecbnh \u0111i\u1ec1u ki\u1ec7n \u0111\u1ec3 k\u1ebft n\u1ed1i hai b\u1ea3ng.<\/span><\/li>\n<\/ul>\n<h3><b>Gi\u1ea3i th\u00edch c\u00e1c lo\u1ea1i JOIN trong MySQL<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Lo\u1ea1i JOIN<\/b><\/td>\n<td><b>M\u00f4 t\u1ea3<\/b><\/td>\n<td><b>K\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1<\/b><\/td>\n<td><b>V\u00ed d\u1ee5 minh h\u1ecda<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">INNER JOIN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1ec9 l\u1ea5y nh\u1eefng b\u1ea3n ghi \u1edf hai b\u1ea3ng c\u00f3 gi\u00e1 tr\u1ecb kh\u1edbp \u1edf c\u1ea3 hai b\u1ea3ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1ec9 d\u1eef li\u1ec7u giao nhau gi\u1eefa hai b\u1ea3ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: T\u00ecm ki\u1ebfm th\u00f4ng tin kh\u00e1ch h\u00e0ng t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">KHACHHANG<\/span><\/i><span style=\"font-weight: 400;\"> c\u00f3 \u0111\u01a1n \u0111\u1eb7t h\u00e0ng trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">DONHANG<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">LEFT JOIN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u1ea5y to\u00e0n b\u1ed9 b\u1ea3n ghi t\u1eeb b\u1ea3ng b\u00ean tr\u00e1i (table1), k\u1ec3 c\u1ea3 khi kh\u00f4ng c\u00f3 b\u1ea3n ghi kh\u1edbp \u1edf b\u1ea3ng b\u00ean ph\u1ea3i.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u kh\u1edbp t\u1eeb hai b\u1ea3ng \u0111\u01b0\u1ee3c join v\u00e0 d\u1eef li\u1ec7u t\u1eeb b\u1ea3ng tr\u00e1i + NULL cho d\u1eef li\u1ec7u kh\u00f4ng kh\u1edbp \u1edf b\u1ea3ng ph\u1ea3i.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: L\u1ea5y danh s\u00e1ch to\u00e0n b\u1ed9 kh\u00e1ch h\u00e0ng t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">KHACHHANG<\/span><\/i><span style=\"font-weight: 400;\">, k\u1ec3 c\u1ea3 nh\u1eefng kh\u00e1ch h\u00e0ng kh\u00f4ng c\u00f3 \u0111\u01a1n \u0111\u1eb7t h\u00e0ng trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">DONHANG<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">RIGHT JOIN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u1ea5y to\u00e0n b\u1ed9 b\u1ea3n ghi t\u1eeb b\u1ea3ng b\u00ean ph\u1ea3i (table2), k\u1ec3 c\u1ea3 khi kh\u00f4ng c\u00f3 b\u1ea3n ghi kh\u1edbp \u1edf b\u1ea3ng b\u00ean tr\u00e1i.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u kh\u1edbp t\u1eeb hai b\u1ea3ng \u0111\u01b0\u1ee3c join v\u00e0 d\u1eef li\u1ec7u t\u1eeb b\u1ea3ng ph\u1ea3i + NULL cho d\u1eef li\u1ec7u kh\u00f4ng kh\u1edbp \u1edf b\u1ea3ng tr\u00e1i.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: L\u1ea5y danh s\u00e1ch t\u1ea5t c\u1ea3 \u0111\u01a1n h\u00e0ng t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">DONHANG<\/span><\/i><span style=\"font-weight: 400;\">, k\u1ec3 c\u1ea3 nh\u1eefng \u0111\u01a1n h\u00e0ng kh\u00f4ng c\u00f3 kh\u00e1ch h\u00e0ng t\u01b0\u01a1ng \u1ee9ng trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">KHACHHANG<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">FULL JOIN (MySQL kh\u00f4ng h\u1ed7 tr\u1ee3 tr\u1ef1c ti\u1ebfp)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">K\u1ebft h\u1ee3p t\u1ea5t c\u1ea3 b\u1ea3n ghi t\u1eeb c\u1ea3 hai b\u1ea3ng, th\u00eam NULL v\u00e0o nh\u1eefng n\u01a1i kh\u00f4ng kh\u1edbp.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u t\u1eeb c\u1ea3 hai b\u1ea3ng, bao g\u1ed3m nh\u1eefng b\u1ea3n ghi kh\u00f4ng kh\u1edbp.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: T\u1ed5ng h\u1ee3p danh s\u00e1ch to\u00e0n b\u1ed9 kh\u00e1ch h\u00e0ng t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">KHACHHANG<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 \u0111\u01a1n h\u00e0ng t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">DONHANG<\/span><\/i><span style=\"font-weight: 400;\">, k\u1ec3 c\u1ea3 nh\u1eefng kh\u00e1ch h\u00e0ng ho\u1eb7c \u0111\u01a1n h\u00e0ng kh\u00f4ng c\u00f3 li\u00ean k\u1ebft.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CROSS JOIN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">K\u1ebft h\u1ee3p t\u1ea5t c\u1ea3 c\u00e1c b\u1ea3n ghi t\u1eeb b\u1ea3ng n\u00e0y v\u1edbi t\u1ea5t c\u1ea3 c\u00e1c b\u1ea3n ghi t\u1eeb b\u1ea3ng kia.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u00edch Descartes (Cartesian Product) c\u1ee7a hai b\u1ea3ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">K\u1ebft h\u1ee3p t\u1ea5t c\u1ea3 kh\u00e1ch h\u00e0ng t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">KHACHHANG<\/span><\/i><span style=\"font-weight: 400;\"> v\u1edbi t\u1ea5t c\u1ea3 s\u1ea3n ph\u1ea9m t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">SANPHAM<\/span><\/i><span style=\"font-weight: 400;\">, \u0111\u1ec3 li\u1ec7t k\u00ea m\u1ecdi kh\u1ea3 n\u0103ng k\u1ebft h\u1ee3p kh\u00e1ch h\u00e0ng v\u1edbi s\u1ea3n ph\u1ea9m.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SELF JOIN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u1ef1c hi\u1ec7n join ch\u00ednh b\u1ea3ng \u0111\u00f3 v\u1edbi ch\u00ednh n\u00f3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u01b0\u01a1ng t\u1ef1 c\u00e1c lo\u1ea1i JOIN kh\u00e1c, nh\u01b0ng \u00e1p d\u1ee5ng tr\u00ean m\u1ed9t b\u1ea3ng duy nh\u1ea5t \u0111\u1ec3 so s\u00e1nh ho\u1eb7c t\u00ecm li\u00ean k\u1ebft trong b\u1ea3ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u00ecm nh\u00e2n vi\u00ean t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">NHANVIEN<\/span><\/i><span style=\"font-weight: 400;\"> c\u00f3 ng\u01b0\u1eddi qu\u1ea3n l\u00fd (tr\u01b0\u1eddng <\/span><i><span style=\"font-weight: 400;\">MANAGER_ID<\/span><\/i><span style=\"font-weight: 400;\">) l\u00e0 nh\u00e2n vi\u00ean kh\u00e1c trong c\u00f9ng b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">NHANVIEN<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Gi\u1ea3 s\u1eed ta c\u00f3 hai b\u1ea3ng sau:<\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">B\u1ea3ng Customers:<\/span><\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><b>CustomerID<\/b><\/td>\n<td><b>Name<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Bob<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li><span style=\"font-weight: 400;\">B\u1ea3ng Orders:<\/span><\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><b>OrderID<\/b><\/td>\n<td><b>CustomerID<\/b><\/td>\n<td><b>Product<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">101<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Laptop<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">102<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Phone<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">103<\/span><\/td>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tablet<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 l\u1ea5y danh s\u00e1ch kh\u00e1ch h\u00e0ng v\u00e0 s\u1ea3n ph\u1ea9m m\u00e0 h\u1ecd \u0111\u00e3 \u0111\u1eb7t h\u00e0ng, ta s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">INNER JOIN<\/span><span style=\"font-weight: 400;\"> nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT Customers.Name, Orders.Product\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Customers\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">INNER JOIN Orders\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON Customers.CustomerID = Orders.CustomerID;<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3<\/b><span style=\"font-weight: 400;\">: Ch\u1ec9 c\u00e1c h\u00e0ng c\u00f3 <\/span><span style=\"font-weight: 400;\">CustomerID<\/span><span style=\"font-weight: 400;\"> tr\u00f9ng kh\u1edbp gi\u1eefa hai b\u1ea3ng m\u1edbi \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 (kh\u00e1ch h\u00e0ng <\/span><span style=\"font-weight: 400;\">John<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">Alice<\/span><span style=\"font-weight: 400;\">) nh\u01b0 sau:<\/span><\/p>\n<table>\n<thead>\n<tr>\n<th><b>Name<\/b><\/th>\n<th><b>Product<\/b><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">John<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Laptop<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Alice<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Phone<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 l\u1ea5y danh s\u00e1ch t\u1ea5t c\u1ea3 kh\u00e1ch h\u00e0ng, k\u00e8m theo s\u1ea3n ph\u1ea9m m\u00e0 h\u1ecd \u0111\u00e3 \u0111\u1eb7t (n\u1ebfu c\u00f3), ta s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">LEFT JOIN<\/span><span style=\"font-weight: 400;\"> nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT Customers.Name, Orders.Product<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Customers<\/span>\r\n\r\n<span style=\"font-weight: 400;\">LEFT JOIN Orders<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON Customers.CustomerID = Orders.CustomerID;<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3<\/b><span style=\"font-weight: 400;\">: t\u1ea5t c\u1ea3 kh\u00e1ch h\u00e0ng trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Customers<\/span><\/i><span style=\"font-weight: 400;\"> \u0111\u1ec1u \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1. \u0110\u1ed1i v\u1edbi kh\u00e1ch h\u00e0ng <\/span><span style=\"font-weight: 400;\">Bob<\/span><span style=\"font-weight: 400;\">, kh\u00f4ng c\u00f3 \u0111\u01a1n h\u00e0ng n\u00e0o kh\u1edbp trong b\u1ea3ng <\/span><span style=\"font-weight: 400;\">Orders<\/span><span style=\"font-weight: 400;\">, n\u00ean gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">Product<\/span><span style=\"font-weight: 400;\"> l\u00e0 <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Name<\/b><\/td>\n<td><b>Product<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">John<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Laptop<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Alice<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Phone<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Bob<\/span><\/td>\n<td><span style=\"font-weight: 400;\">NULL<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 l\u1ea5y danh s\u00e1ch t\u1ea5t c\u1ea3 c\u00e1c s\u1ea3n ph\u1ea9m \u0111\u00e3 \u0111\u01b0\u1ee3c \u0111\u1eb7t h\u00e0ng, k\u00e8m theo t\u00ean kh\u00e1ch h\u00e0ng (n\u1ebfu c\u00f3), ta s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">RIGHT JOIN<\/span><span style=\"font-weight: 400;\"> nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT Customers.Name, Orders.Product<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Customers<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RIGHT JOIN Orders<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON Customers.CustomerID = Orders.CustomerID;<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3<\/b><span style=\"font-weight: 400;\">: t\u1ea5t c\u1ea3 c\u00e1c \u0111\u01a1n h\u00e0ng trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Orders<\/span><\/i><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1. S\u1ea3n ph\u1ea9m <\/span><span style=\"font-weight: 400;\">Tablet<\/span><span style=\"font-weight: 400;\"> kh\u00f4ng kh\u1edbp v\u1edbi b\u1ea5t k\u1ef3 kh\u00e1ch h\u00e0ng n\u00e0o trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Customers<\/span><\/i><span style=\"font-weight: 400;\">, n\u00ean gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">Name<\/span><span style=\"font-weight: 400;\"> l\u00e0 <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Name<\/b><\/td>\n<td><b>Product<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">John<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Laptop<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Alice<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Phone<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">NULL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tablet<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 l\u1ea5y danh s\u00e1ch \u0111\u1ea7y \u0111\u1ee7 t\u1ea5t c\u1ea3 kh\u00e1ch h\u00e0ng v\u00e0 s\u1ea3n ph\u1ea9m \u0111\u00e3 \u0111\u1eb7t h\u00e0ng trong MySQL, ta c\u1ea7n s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">UNION<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 k\u1ebft h\u1ee3p hai c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">LEFT JOIN<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">RIGHT JOIN<\/span><span style=\"font-weight: 400;\"> nh\u01b0 sau:\u00a0<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT Customers.Name, Orders.Product<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Customers<\/span>\r\n\r\n<span style=\"font-weight: 400;\">LEFT JOIN Orders<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON Customers.CustomerID = Orders.CustomerID<\/span>\r\n\r\n<span style=\"font-weight: 400;\">UNION<\/span>\r\n\r\n<span style=\"font-weight: 400;\">SELECT Customers.Name, Orders.Product<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Customers<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RIGHT JOIN Orders<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON Customers.CustomerID = Orders.CustomerID;<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3<\/b><span style=\"font-weight: 400;\">: tr\u1ea3 v\u1ec1 t\u1ea5t c\u1ea3 c\u00e1c h\u00e0ng t\u1eeb <\/span><i><span style=\"font-weight: 400;\">Customers<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 <\/span><i><span style=\"font-weight: 400;\">Orders<\/span><\/i><span style=\"font-weight: 400;\">. Kh\u00e1ch h\u00e0ng <\/span><span style=\"font-weight: 400;\">Bob<\/span><span style=\"font-weight: 400;\"> kh\u00f4ng c\u00f3 \u0111\u01a1n h\u00e0ng n\u00e0o, c\u00f2n s\u1ea3n ph\u1ea9m <\/span><span style=\"font-weight: 400;\">Tablet<\/span><span style=\"font-weight: 400;\"> kh\u00f4ng kh\u1edbp v\u1edbi b\u1ea5t k\u1ef3 kh\u00e1ch h\u00e0ng n\u00e0o.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Name<\/b><\/td>\n<td><b>Product<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">John<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Laptop<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Alice<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Phone<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Bob<\/span><\/td>\n<td><span style=\"font-weight: 400;\">NULL<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">NULL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tablet<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>MySQL WorkBench l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">MySQL Workbench l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 tr\u1ef1c quan (GUI &#8211; Graphical User Interface) \u0111\u01b0\u1ee3c ph\u00e1t tri\u1ec3n b\u1edfi Oracle Corporation \u0111\u1ec3 qu\u1ea3n l\u00fd c\u01a1 s\u1edf d\u1eef li\u1ec7u. N\u00f3 cung c\u1ea5p c\u00e1c t\u00ednh n\u0103ng m\u1ea1nh m\u1ebd cho vi\u1ec7c thi\u1ebft k\u1ebf, ph\u00e1t tri\u1ec3n, v\u00e0 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u MySQL.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00f4ng c\u1ee5 n\u00e0y \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng r\u1ed9ng r\u00e3i nh\u1edd giao di\u1ec7n th\u00e2n thi\u1ec7n v\u00e0 kh\u1ea3 n\u0103ng h\u1ed7 tr\u1ee3 \u0111a n\u1ec1n t\u1ea3ng (Windows, macOS, Linux).<\/span><\/p>\n<h4><b>C\u00e1c t\u00ednh n\u0103ng ch\u00ednh c\u1ee7a MySQL Workbench<\/b><\/h4>\n<table>\n<tbody>\n<tr>\n<td><b>T\u00ednh n\u0103ng<\/b><\/td>\n<td><b>M\u00f4 t\u1ea3<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Database Design<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Cho ph\u00e9p thi\u1ebft k\u1ebf, t\u1ea1o v\u00e0 ch\u1ec9nh s\u1eeda m\u00f4 h\u00ecnh d\u1eef li\u1ec7u b\u1eb1ng c\u00e1ch k\u00e9o th\u1ea3 (ER Diagram).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; H\u1ed7 tr\u1ee3 t\u1ea1o s\u01a1 \u0111\u1ed3 ER (Entity-Relationship) v\u00e0 sinh m\u00e3 SQL t\u1ef1 \u0111\u1ed9ng t\u1eeb m\u00f4 h\u00ecnh.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SQL Development<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Cung c\u1ea5p giao di\u1ec7n \u0111\u1ec3 vi\u1ebft, ch\u1ea1y v\u00e0 ki\u1ec3m tra c\u00e1c c\u00e2u l\u1ec7nh SQL.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Hi\u1ec3n th\u1ecb k\u1ebft qu\u1ea3 truy v\u1ea5n tr\u1ef1c ti\u1ebfp, l\u01b0u c\u00e1c truy v\u1ea5n d\u01b0\u1edbi d\u1ea1ng t\u1ec7p .sql.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; C\u00f3 tr\u00ecnh bi\u00ean d\u1ecbch SQL t\u00edch h\u1ee3p v\u00e0 c\u00f4ng c\u1ee5 g\u1ee1 l\u1ed7i SQL.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Database Administration<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Qu\u1ea3n l\u00fd ng\u01b0\u1eddi d\u00f9ng, quy\u1ec1n truy c\u1eadp, sao l\u01b0u v\u00e0 ph\u1ee5c h\u1ed3i c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Data Modeling<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ea1o m\u00f4 h\u00ecnh c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u1eadt l\u00fd, logic v\u00e0 chuy\u1ec3n \u0111\u1ed5i qua l\u1ea1i gi\u1eefa c\u00e1c d\u1ea1ng.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Performance Monitoring<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Theo d\u00f5i hi\u1ec7u n\u0103ng c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 t\u1ed1i \u01b0u h\u00f3a c\u00e1c truy v\u1ea5n.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Migration<\/span><\/td>\n<td><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3 chuy\u1ec3n \u0111\u1ed5i d\u1eef li\u1ec7u t\u1eeb c\u00e1c h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u kh\u00e1c sang MySQL.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>\u1ee8ng d\u1ee5ng c\u1ee7a MySQL Workbench<\/strong><\/h4>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Thi\u1ebft k\u1ebf c\u01a1 s\u1edf d\u1eef li\u1ec7u<\/b><span style=\"font-weight: 400;\">: M\u1ed9t c\u00f4ng ty c\u1ea7n thi\u1ebft k\u1ebf s\u01a1 \u0111\u1ed3 quan h\u1ec7 cho h\u1ec7 th\u1ed1ng b\u00e1n h\u00e0ng, MySQL Workbench h\u1ed7 tr\u1ee3 t\u1ea1o ERD (Entity-Relationship Diagram) v\u00e0 t\u1ef1 \u0111\u1ed9ng chuy\u1ec3n \u0111\u1ed5i th\u00e0nh m\u00e3 SQL.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ph\u00e2n t\u00edch d\u1eef li\u1ec7u<\/b><span style=\"font-weight: 400;\">: Ch\u1ea1y truy v\u1ea5n \u0111\u1ec3 th\u1ed1ng k\u00ea v\u00e0 ph\u00e2n t\u00edch d\u1eef li\u1ec7u kinh doanh.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u<\/b><span style=\"font-weight: 400;\">: Qu\u1ea3n l\u00fd t\u00e0i kho\u1ea3n ng\u01b0\u1eddi d\u00f9ng, ph\u00e2n quy\u1ec1n, sao l\u01b0u d\u1eef li\u1ec7u \u0111\u1ecbnh k\u1ef3.<\/span><\/li>\n<\/ul>\n<h4><strong>\u01afu \u0111i\u1ec3m c\u1ee7a MySQL Workbench<\/strong><\/h4>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Th\u00e2n thi\u1ec7n v\u1edbi ng\u01b0\u1eddi d\u00f9ng: <\/b><span style=\"font-weight: 400;\">Giao di\u1ec7n \u0111\u1ed3 h\u1ecda tr\u1ef1c quan, d\u1ec5 s\u1eed d\u1ee5ng, ngay c\u1ea3 v\u1edbi ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ti\u1ebft ki\u1ec7m th\u1eddi gian:<\/b><span style=\"font-weight: 400;\"> C\u00e1c c\u00f4ng c\u1ee5 nh\u01b0 k\u00e9o th\u1ea3 m\u00f4 h\u00ecnh, t\u1ef1 \u0111\u1ed9ng sinh m\u00e3 SQL gi\u00fap gi\u1ea3m th\u1eddi gian thao t\u00e1c th\u1ee7 c\u00f4ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>H\u1ed7 tr\u1ee3 to\u00e0n di\u1ec7n: <\/b><span style=\"font-weight: 400;\">T\u00edch h\u1ee3p \u0111\u1ea7y \u0111\u1ee7 c\u00e1c t\u00ednh n\u0103ng t\u1eeb thi\u1ebft k\u1ebf, ph\u00e1t tri\u1ec3n \u0111\u1ebfn qu\u1ea3n tr\u1ecb.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Hi\u1ec7u qu\u1ea3 cao: <\/b><span style=\"font-weight: 400;\">Gi\u00fap qu\u1ea3n l\u00fd c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u l\u1edbn v\u00e0 ph\u1ee9c t\u1ea1p m\u1ed9t c\u00e1ch d\u1ec5 d\u00e0ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Mi\u1ec5n ph\u00ed: <\/b><span style=\"font-weight: 400;\">Phi\u00ean b\u1ea3n Community Edition mi\u1ec5n ph\u00ed v\u00e0 \u0111\u00e1p \u1ee9ng h\u1ea7u h\u1ebft c\u00e1c nhu c\u1ea7u c\u01a1 b\u1ea3n.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cac_cau_hoi_phong_van_MySQL_thuong_gap_danh_cho_Intermediate\"><\/span><b>C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL th\u01b0\u1eddng g\u1eb7p d\u00e0nh cho Intermediate<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>C\u00e1ch t\u00ecm duplicate row trong MySQL<\/b><\/h3>\n<h4><b>C\u00e1ch 1: D\u00f9ng <\/b><b>GROUP BY<\/b><b> v\u00e0 <\/b><b>HAVING<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Ph\u01b0\u01a1ng ph\u00e1p n\u00e0y gom nh\u00f3m c\u00e1c b\u1ea3n ghi d\u1ef1a tr\u00ean c\u00e1c c\u1ed9t \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh v\u00e0 s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">COUNT(*)<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 \u0111\u1ebfm s\u1ed1 l\u1ea7n xu\u1ea5t hi\u1ec7n trong t\u1eebng nh\u00f3m.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed ta c\u00f3 b\u1ea3ng employees nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>age<\/b><\/td>\n<td><b>department<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">30<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<td><span style=\"font-weight: 400;\">25<\/span><\/td>\n<td><span style=\"font-weight: 400;\">HR<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">30<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice Brown<\/span><\/td>\n<td><span style=\"font-weight: 400;\">28<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Marketing<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">30<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u00ecm c\u00e1c b\u1ea3n ghi c\u00f3 gi\u00e1 tr\u1ecb tr\u00f9ng l\u1eb7p tr\u00ean c\u00e1c c\u1ed9t <\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">age<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">department<\/span><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT name, age, department, COUNT(*) AS duplicate_count\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM employees\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">GROUP BY name, age, department<\/span>\r\n\r\n<span style=\"font-weight: 400;\">HAVING COUNT(*) &gt; 1;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">GROUP BY name, age, department<\/span><b>:<\/b><span style=\"font-weight: 400;\"> Gom nh\u00f3m c\u00e1c b\u1ea3n ghi d\u1ef1a tr\u00ean t\u1ed5 h\u1ee3p c\u00e1c gi\u00e1 tr\u1ecb <\/span><i><span style=\"font-weight: 400;\">name<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">age<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 <\/span><i><span style=\"font-weight: 400;\">department<\/span><\/i><span style=\"font-weight: 400;\">. T\u1ea5t c\u1ea3 c\u00e1c b\u1ea3n ghi c\u00f3 c\u00f9ng gi\u00e1 tr\u1ecb trong c\u00e1c c\u1ed9t n\u00e0y s\u1ebd \u0111\u01b0\u1ee3c gom th\u00e0nh m\u1ed9t nh\u00f3m.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">COUNT(*)<\/span><b>:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ebfm s\u1ed1 b\u1ea3n ghi trong m\u1ed7i nh\u00f3m.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">HAVING COUNT(*) &gt; 1<\/span><b>:<\/b><span style=\"font-weight: 400;\"> L\u1ecdc ra ch\u1ec9 nh\u1eefng nh\u00f3m c\u00f3 h\u01a1n 1 b\u1ea3n ghi (t\u1ee9c l\u00e0 tr\u00f9ng l\u1eb7p).<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u1edbi c\u00fa ph\u00e1p tr\u00ean s\u1ebd tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>name<\/b><\/td>\n<td><b>age<\/b><\/td>\n<td><b>department<\/b><\/td>\n<td><b>duplicate_count<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">30<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Ti\u1ebfp theo, \u0111\u1ec3 t\u00ecm t\u1ed5ng s\u1ed1 b\u1ea3n ghi b\u1ecb tr\u00f9ng l\u1eb7p trong b\u1ea3ng m\u00e0 kh\u00f4ng li\u1ec7t k\u00ea chi ti\u1ebft t\u1eebng nh\u00f3m ta c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT SUM(duplicate_count - 1) AS total_duplicates\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM (\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0SELECT COUNT(*) AS duplicate_count\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0FROM employees\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0GROUP BY name, age, department\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0HAVING COUNT(*) &gt; 1\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">AS duplicates;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">GROUP BY name<\/span><b>, <\/b><span style=\"font-weight: 400;\">age<\/span><b>, <\/b><span style=\"font-weight: 400;\">department<\/span><b>:<\/b><span style=\"font-weight: 400;\"> Gom nh\u00f3m c\u00e1c b\u1ea3n ghi tr\u00f9ng l\u1eb7p.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">COUNT(*)<\/span><b>:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ebfm s\u1ed1 l\u01b0\u1ee3ng b\u1ea3n ghi trong m\u1ed7i nh\u00f3m.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">HAVING COUNT(*) &gt; 1<\/span><b>:<\/b><span style=\"font-weight: 400;\"> L\u1ecdc ra c\u00e1c nh\u00f3m c\u00f3 b\u1ea3n ghi tr\u00f9ng l\u1eb7p.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">SUM(duplicate_count &#8211; 1)<\/span><b>:<\/b><span style=\"font-weight: 400;\"> T\u00ednh t\u1ed5ng s\u1ed1 b\u1ea3n ghi tr\u00f9ng l\u1eb7p (tr\u1eeb 1 b\u1ea3n ghi duy nh\u1ea5t cho m\u1ed7i nh\u00f3m).<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u1edbi c\u00fa ph\u00e1p tr\u00ean k\u1ebft qu\u1ea3 s\u1ebd tr\u1ea3 v\u1ec1 nh\u01b0 sau v\u00ec c\u00f3 t\u1ed5ng c\u1ed9ng 2 b\u1ea3n ghi b\u1ecb tr\u00f9ng l\u1eb7p (nh\u00f3m &#8220;John Doe &#8211; 30 &#8211; IT&#8221;):<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">total_duplicates = 2<\/span><\/pre>\n<h4><b>C\u00e1ch 2: D\u00f9ng <\/b><b>DISTINCT<\/b><b> \u0111\u1ec3 so s\u00e1nh<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">N\u1ebfu mu\u1ed1n so s\u00e1nh c\u00e1c b\u1ea3n ghi duy nh\u1ea5t v\u00e0 c\u00e1c b\u1ea3n ghi tr\u00f9ng l\u1eb7p, ta c\u00f3 th\u1ec3 d\u00f9ng <\/span><span style=\"font-weight: 400;\">DISTINCT<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh s\u1ed1 l\u01b0\u1ee3ng b\u1ea3n ghi duy nh\u1ea5t v\u00e0 t\u1ed5ng s\u1ed1 b\u1ea3n ghi.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0(SELECT COUNT(*) FROM employees) AS total_records,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0(SELECT COUNT(DISTINCT name, age, department) FROM employees) AS unique_records,<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0(SELECT COUNT(*) FROM employees) - (SELECT COUNT(DISTINCT name, age, department) FROM employees) AS duplicate_records;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">COUNT(*<\/span><b>)<\/b><b>:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ebfm t\u1ed5ng s\u1ed1 b\u1ea3n ghi trong b\u1ea3ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">COUNT(DISTINCT name, age, department)<\/span><b>:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ebfm s\u1ed1 b\u1ea3n ghi duy nh\u1ea5t (lo\u1ea1i b\u1ecf b\u1ea3n ghi tr\u00f9ng l\u1eb7p d\u1ef1a tr\u00ean c\u00e1c c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">name<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">age<\/span><\/i><span style=\"font-weight: 400;\">,v\u00e0 <\/span><i><span style=\"font-weight: 400;\">department<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ph\u00e9p tr\u1eeb: S\u1ed1 b\u1ea3n ghi tr\u00f9ng l\u1eb7p = T\u1ed5ng s\u1ed1 b\u1ea3n ghi &#8211; S\u1ed1 b\u1ea3n ghi duy nh\u1ea5t.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1 s\u1ebd nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">total_records = 5\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">unique_records = 3\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">duplicate_records = 2<\/span><\/pre>\n<h3><b>Gi\u1ea3i th\u00edch c\u00e1c lo\u1ea1i quan h\u1ec7 trong MySQL<\/b><\/h3>\n<h4><b>Quan h\u1ec7 One-to-One (1:1)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">C\u00f3 ngh\u0129a l\u00e0 m\u1ed9t b\u1ea3n ghi trong b\u1ea3ng n\u00e0y ch\u1ec9 c\u00f3 th\u1ec3 li\u00ean k\u1ebft v\u1edbi m\u1ed9t b\u1ea3n ghi duy nh\u1ea5t trong b\u1ea3ng kh\u00e1c v\u00e0 ng\u01b0\u1ee3c l\u1ea1i. V\u00ed d\u1ee5 m\u1ed9t ng\u01b0\u1eddi d\u00f9ng (users) ch\u1ec9 c\u00f3 m\u1ed9t h\u1ed3 s\u01a1 c\u00e1 nh\u00e2n (profiles).<\/span><\/p>\n<p><b>C\u00e1ch thi\u1ebft l\u1eadp<\/b><span style=\"font-weight: 400;\">: S\u1eed d\u1ee5ng Primary Key tr\u00ean m\u1ed9t b\u1ea3ng v\u00e0 li\u00ean k\u1ebft v\u1edbi Foreign Key trong b\u1ea3ng kia v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TABLE users ( <\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0id INT PRIMARY KEY,\u00a0<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0name VARCHAR(100)\u00a0<\/span>\r\n<span style=\"font-weight: 400;\">);\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CREATE TABLE profiles ( <\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0id INTPRIMARY KEY,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0user_id INT UNIQUE,\u00a0<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0bio TEXT,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0FOREIGN KEY (user_id) REFERENCES users(id)\u00a0<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3: m\u1ed7i <\/span><i><span style=\"font-weight: 400;\">user<\/span><\/i><span style=\"font-weight: 400;\"> c\u00f3 m\u1ed9t <\/span><i><span style=\"font-weight: 400;\">profile<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">user_id<\/span><\/i><span style=\"font-weight: 400;\"> trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">profiles<\/span><\/i><span style=\"font-weight: 400;\"> li\u00ean k\u1ebft v\u1edbi c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">id<\/span><\/i><span style=\"font-weight: 400;\"> trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">users<\/span><\/i><span style=\"font-weight: 400;\">. V\u00ec c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">user_id <\/span><\/i><span style=\"font-weight: 400;\">\u0111\u01b0\u1ee3c r\u00e0ng bu\u1ed9c UNIQUE n\u00ean m\u1ed7i user_id ch\u1ec9 xu\u1ea5t hi\u1ec7n m\u1ed9t l\u1ea7n trong b\u1ea3ng profile.<\/span><\/p>\n<h4><b>Quan h\u1ec7 One-to-Many (1:N)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">C\u00f3 ngh\u0129a l\u00e0 m\u1ed9t b\u1ea3n ghi trong b\u1ea3ng A c\u00f3 th\u1ec3 li\u00ean k\u1ebft v\u1edbi nhi\u1ec1u b\u1ea3n ghi trong b\u1ea3ng B, nh\u01b0ng m\u1ed7i b\u1ea3n ghi trong b\u1ea3ng B ch\u1ec9 li\u00ean k\u1ebft v\u1edbi m\u1ed9t b\u1ea3n ghi trong b\u1ea3ng A. V\u00ed d\u1ee5 m\u1ed9t kh\u00e1ch h\u00e0ng (customers) c\u00f3 th\u1ec3 \u0111\u1eb7t nhi\u1ec1u \u0111\u01a1n h\u00e0ng (orders), nh\u01b0ng m\u1ed7i \u0111\u01a1n h\u00e0ng ch\u1ec9 thu\u1ed9c v\u1ec1 m\u1ed9t kh\u00e1ch h\u00e0ng.<\/span><\/p>\n<p><b>C\u00e1ch thi\u1ebft l\u1eadp<\/b><span style=\"font-weight: 400;\">: S\u1eed d\u1ee5ng Primary Key trong b\u1ea3ng cha (parent table) v\u00e0 li\u00ean k\u1ebft v\u1edbi Foreign Key trong b\u1ea3ng con (child table) v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TABLE customers (<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0id INT PRIMARY KEY,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0name VARCHAR(100)<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CREATE TABLE orders (<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0id INT PRIMARY KEY,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0customer_id INT NOT NULL,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0order_date DATE,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0FOREIGN KEY (customer_id) REFERENCES customers(id)<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3: m\u1ed7i <\/span><i><span style=\"font-weight: 400;\">customer<\/span><\/i><span style=\"font-weight: 400;\"> c\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u <\/span><i><span style=\"font-weight: 400;\">order<\/span><\/i><span style=\"font-weight: 400;\">, nh\u01b0ng m\u1ed7i <\/span><i><span style=\"font-weight: 400;\">order<\/span><\/i><span style=\"font-weight: 400;\"> ch\u1ec9 thu\u1ed9c v\u1ec1 m\u1ed9t <\/span><i><span style=\"font-weight: 400;\">customer<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><b>Quan h\u1ec7 Many-to-Many (N:M)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">C\u00f3 ngh\u0129a l\u00e0 m\u1ed9t b\u1ea3n ghi trong b\u1ea3ng A c\u00f3 th\u1ec3 li\u00ean k\u1ebft v\u1edbi nhi\u1ec1u b\u1ea3n ghi trong b\u1ea3ng B v\u00e0 ng\u01b0\u1ee3c l\u1ea1i. V\u00ed d\u1ee5 m\u1ed9t sinh vi\u00ean (<\/span><i><span style=\"font-weight: 400;\">students<\/span><\/i><span style=\"font-weight: 400;\">) c\u00f3 th\u1ec3 tham gia nhi\u1ec1u kh\u00f3a h\u1ecdc (<\/span><i><span style=\"font-weight: 400;\">courses<\/span><\/i><span style=\"font-weight: 400;\">) v\u00e0 m\u1ed7i kh\u00f3a h\u1ecdc c\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u sinh vi\u00ean tham gia.<\/span><\/p>\n<p><b>C\u00e1ch thi\u1ebft l\u1eadp:<\/b><span style=\"font-weight: 400;\"> T\u1ea1o m\u1ed9t b\u1ea3ng trung gian (junction table) ch\u1ee9a c\u00e1c Foreign Key li\u00ean k\u1ebft v\u1edbi hai b\u1ea3ng ch\u00ednh v\u1edbi c\u00fa ph\u00e1p nh\u01b0:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TABLE students (<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0id INT PRIMARY KEY,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0name VARCHAR(100)<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CREATE TABLE courses (<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0id INT PRIMARY KEY,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0title VARCHAR(100)<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CREATE TABLE student_courses (<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0student_id INT NOT NULL,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0course_id INT NOT NULL,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0PRIMARY KEY (student_id, course_id),<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0FOREIGN KEY (student_id) REFERENCES students(id),<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0FOREIGN KEY (course_id) REFERENCES courses(id)<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3: b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">student_courses<\/span><\/i><span style=\"font-weight: 400;\"> l\u00e0 b\u1ea3ng trung gian gi\u00fap qu\u1ea3n l\u00fd m\u1ed1i quan h\u1ec7 nhi\u1ec1u-nhi\u1ec1u gi\u1eefa <\/span><i><span style=\"font-weight: 400;\">students<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 <\/span><i><span style=\"font-weight: 400;\">courses<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><b>Quan h\u1ec7 Self-Referencing (T\u1ef1 tham chi\u1ebfu)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">C\u00f3 ngh\u0129a l\u00e0 m\u1ed9t b\u1ea3n ghi trong b\u1ea3ng c\u00f3 th\u1ec3 li\u00ean k\u1ebft v\u1edbi m\u1ed9t b\u1ea3n ghi kh\u00e1c tr\u00ean c\u00f9ng b\u1ea3ng th\u00f4ng qua m\u1ed9t kh\u00f3a ngo\u1ea1i. V\u00ed d\u1ee5 m\u1ed9t nh\u00e2n vi\u00ean (<\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\">) c\u00f3 th\u1ec3 l\u00e0 c\u1ea5p d\u01b0\u1edbi c\u1ee7a m\u1ed9t nh\u00e2n vi\u00ean kh\u00e1c (qu\u1ea3n l\u00fd).<\/span><\/p>\n<p><b>C\u00e1ch thi\u1ebft l\u1eadp:<\/b><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng Foreign Key \u0111\u1ec3 tham chi\u1ebfu \u0111\u1ebfn Primary Key trong c\u00f9ng m\u1ed9t b\u1ea3ng v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TABLE employees (<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0id INT PRIMARY KEY,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0name VARCHAR(100),<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0manager_id INT,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0FOREIGN KEY (manager_id) REFERENCES employees(id)<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3: c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">manager_id<\/span><\/i><span style=\"font-weight: 400;\"> trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> tham chi\u1ebfu \u0111\u1ebfn c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">id<\/span><\/i><span style=\"font-weight: 400;\"> trong c\u00f9ng b\u1ea3ng, th\u1ec3 hi\u1ec7n m\u1ed1i quan h\u1ec7 c\u1ea5p tr\u00ean &#8211; c\u1ea5p d\u01b0\u1edbi.<\/span><\/p>\n<h3><b>S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa primary key v\u00e0 candidate key<\/b><\/h3>\n<p><b>Primary Key<\/b><span style=\"font-weight: 400;\"> l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p m\u1ed9t ho\u1eb7c nhi\u1ec1u c\u1ed9t trong b\u1ea3ng \u0111\u01b0\u1ee3c ch\u1ecdn \u0111\u1ec3 l\u00e0m kh\u00f3a ch\u00ednh v\u00e0 gi\u00fap \u0111\u1ea3m b\u1ea3o r\u1eb1ng m\u1ed7i b\u1ea3n ghi trong b\u1ea3ng \u0111\u01b0\u1ee3c \u0111\u1ecbnh danh duy nh\u1ea5t v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p ch\u1ee9a gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c tr\u00f9ng l\u1eb7p. M\u1ed7i b\u1ea3ng ch\u1ec9 c\u00f3 m\u1ed9t Primary Key duy nh\u1ea5t.<\/span><\/p>\n<p><b>Candidate Key<\/b><span style=\"font-weight: 400;\"> l\u00e0 t\u1eadp h\u1ee3p m\u1ed9t ho\u1eb7c nhi\u1ec1u c\u1ed9t trong b\u1ea3ng c\u00f3 kh\u1ea3 n\u0103ng \u0111\u1ecbnh danh duy nh\u1ea5t m\u1ed9t b\u1ea3n ghi (kh\u00f3a ti\u1ec1m n\u0103ng). M\u1ed9t b\u1ea3ng c\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u Candidate Keys, nh\u01b0ng ch\u1ec9 m\u1ed9t Candidate Key s\u1ebd \u0111\u01b0\u1ee3c ch\u1ecdn l\u00e0m Primary Key. Candidate Key kh\u00f4ng ch\u1ee9a gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c tr\u00f9ng l\u1eb7p.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed ta c\u00f3 b\u1ea3ng sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>emp_id<\/b><\/td>\n<td><b>email<\/b><\/td>\n<td><b>phone<\/b><\/td>\n<td><b>name<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">101<\/span><\/td>\n<td><span style=\"font-weight: 400;\">john.doe@gmail.com<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1234567890<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">102<\/span><\/td>\n<td><span style=\"font-weight: 400;\">jane.smith@gmail.com<\/span><\/td>\n<td><span style=\"font-weight: 400;\">0987654321<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">103<\/span><\/td>\n<td><span style=\"font-weight: 400;\">alice.brown@gmail.com<\/span><\/td>\n<td><span style=\"font-weight: 400;\">5678901234<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice Brown<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c c\u1ed9t ho\u1eb7c t\u1ed5 h\u1ee3p c\u1ed9t c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c coi l\u00e0 Candidate Key v\u00ec ch\u00fang \u0111\u1ec1u duy nh\u1ea5t v\u00e0 kh\u00f4ng ch\u1ee9a gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\"> l\u00e0 <\/span><i><span style=\"font-weight: 400;\">emp_id<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">email<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">phone<\/span><\/i><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u1ed9t c\u00f3 th\u1ec3 l\u00e0m Primary Key ch\u1ec9 c\u00f3 th\u1ec3 l\u00e0 <\/span><i><span style=\"font-weight: 400;\">emp_id<\/span><\/i><span style=\"font-weight: 400;\"> v\u00ec n\u00f3 kh\u00f4ng thay \u0111\u1ed5i theo th\u1eddi gian (trong khi <\/span><i><span style=\"font-weight: 400;\">email<\/span><\/i><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><i><span style=\"font-weight: 400;\">phone<\/span><\/i><span style=\"font-weight: 400;\"> c\u00f3 th\u1ec3 thay \u0111\u1ed5i)<\/span><\/li>\n<\/ul>\n<h3><b>Ph\u00e2n bi\u1ec7t DELETE v\u00e0 TRUNCATE<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Khi l\u00e0m vi\u1ec7c v\u1edbi c\u01a1 s\u1edf d\u1eef li\u1ec7u SQL, vi\u1ec7c x\u00f3a d\u1eef li\u1ec7u l\u00e0 m\u1ed9t thao t\u00e1c ph\u1ed5 bi\u1ebfn. Tuy nhi\u00ean, hai l\u1ec7nh DELETE v\u00e0 TRUNCATE tuy c\u00f9ng d\u00f9ng \u0111\u1ec3 x\u00f3a d\u1eef li\u1ec7u nh\u01b0ng l\u1ea1i c\u00f3 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng v\u00e0 \u1ee9ng d\u1ee5ng kh\u00e1c nhau.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 b\u1ea3ng so s\u00e1nh chi ti\u1ebft gi\u1eefa hai l\u1ec7nh n\u00e0y:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>DELETE<\/b><\/td>\n<td><b>TRUNCATE<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Ch\u1ee9c n\u0103ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">X\u00f3a l\u1ea7n l\u01b0\u1ee3t c\u00e1c b\u1ea3n ghi trong b\u1ea3ng d\u1ef1a tr\u00ean \u0111i\u1ec1u ki\u1ec7n trong m\u1ec7nh \u0111\u1ec1 WHERE.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">X\u00f3a c\u00f9ng l\u00fac to\u00e0n b\u1ed9 d\u1eef li\u1ec7u trong b\u1ea3ng m\u00e0 kh\u00f4ng th\u1ec3 \u0111\u1eb7t \u0111i\u1ec1u ki\u1ec7n.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Kh\u00f4i ph\u1ee5c d\u1eef li\u1ec7u<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 kh\u00f4i ph\u1ee5c b\u1eb1ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">ROLLBACK<\/span><span style=\"font-weight: 400;\"> n\u1ebfu \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong giao d\u1ecbch (<\/span><i><span style=\"font-weight: 400;\">transaction<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng th\u1ec3 kh\u00f4i ph\u1ee5c v\u00ec kh\u00f4ng h\u1ed7 tr\u1ee3 giao d\u1ecbch (m\u1eb7c \u0111\u1ecbnh l\u00e0 l\u1ec7nh kh\u00f4ng th\u1ec3 ho\u00e0n t\u00e1c).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hi\u1ec7u n\u0103ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1eadm h\u01a1n, v\u00ec ph\u1ea3i th\u1ef1c hi\u1ec7n x\u00f3a l\u1ea7n l\u01b0\u1ee3t t\u1eebng b\u1ea3n ghi. M\u1ed7i b\u1ea3n ghi b\u1ecb x\u00f3a \u0111\u01b0\u1ee3c ghi l\u1ea1i trong log, v\u00e0 trigger (n\u1ebfu c\u00f3) s\u1ebd \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Nhanh h\u01a1n, v\u00ec x\u00f3a to\u00e0n b\u1ed9 d\u1eef li\u1ec7u kh\u00f4ng ghi log t\u1eebng b\u1ea3n ghi v\u00e0 kh\u00f4ng k\u00edch ho\u1ea1t trigger.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u1ea5p \u0111\u1ed9 kh\u00f3a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng kh\u00f3a d\u00f2ng (<\/span><i><span style=\"font-weight: 400;\">row-level lock<\/span><\/i><span style=\"font-weight: 400;\">), cho ph\u00e9p x\u00f3a d\u1eef li\u1ec7u theo \u0111i\u1ec1u ki\u1ec7n c\u1ee5 th\u1ec3.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng kh\u00f3a b\u1ea3ng (<\/span><i><span style=\"font-weight: 400;\">table-level lock<\/span><\/i><span style=\"font-weight: 400;\">), v\u00ec x\u00f3a to\u00e0n b\u1ed9 b\u1ea3ng.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ea2nh h\u01b0\u1edfng \u0111\u1ebfn c\u1ea5u tr\u00fac b\u1ea3ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn c\u1ea5u tr\u00fac b\u1ea3ng, c\u00e1c ch\u1ec9 m\u1ee5c v\u00e0 kh\u00f3a v\u1eabn \u0111\u01b0\u1ee3c gi\u1eef nguy\u00ean.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Gi\u1eef nguy\u00ean c\u1ea5u tr\u00fac b\u1ea3ng, nh\u01b0ng c\u00e1c ch\u1ec9 m\u1ee5c v\u00e0 kh\u00f3a s\u1ebd \u0111\u01b0\u1ee3c \u0111\u1eb7t l\u1ea1i (reset AUTO_INCREMENT).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Khi n\u00e0o s\u1eed d\u1ee5ng?<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng khi c\u1ea7n x\u00f3a d\u1eef li\u1ec7u c\u00f3 \u0111i\u1ec1u ki\u1ec7n ho\u1eb7c c\u1ea7n ki\u1ec3m so\u00e1t qu\u00e1 tr\u00ecnh x\u00f3a qua giao d\u1ecbch.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng khi c\u1ea7n x\u00f3a nhanh to\u00e0n b\u1ed9 d\u1eef li\u1ec7u trong b\u1ea3ng m\u00e0 kh\u00f4ng c\u1ea7n ki\u1ec3m tra \u0111i\u1ec1u ki\u1ec7n.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">DELETE FROM table_name WHERE condition;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">TRUNCATE TABLE table_name;<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Ch\u1ec9 m\u1ee5c (Index) trong MySQL l\u00e0 g\u00ec? T\u1ea1i sao n\u00f3 quan tr\u1ecdng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ch\u1ec9 m\u1ee5c (Index) trong MySQL l\u00e0 m\u1ed9t c\u1ea5u tr\u00fac d\u1eef li\u1ec7u \u0111\u1eb7c bi\u1ec7t \u0111\u01b0\u1ee3c t\u1ea1o ra t\u1eeb m\u1ed9t ho\u1eb7c nhi\u1ec1u c\u1ed9t,\u00a0 s\u1eed d\u1ee5ng \u0111\u1ec3 t\u0103ng t\u1ed1c \u0111\u1ed9 truy v\u1ea5n d\u1eef li\u1ec7u trong b\u1ea3ng. Ch\u1ec9 m\u1ee5c ho\u1ea1t \u0111\u1ed9ng t\u01b0\u01a1ng t\u1ef1 nh\u01b0 m\u1ee5c l\u1ee5c c\u1ee7a m\u1ed9t cu\u1ed1n s\u00e1ch: thay v\u00ec ph\u1ea3i duy\u1ec7t qua to\u00e0n b\u1ed9 d\u1eef li\u1ec7u trong b\u1ea3ng, MySQL c\u00f3 th\u1ec3 nhanh ch\u00f3ng t\u00ecm \u0111\u1ebfn v\u1ecb tr\u00ed d\u1eef li\u1ec7u c\u1ee5 th\u1ec3 d\u1ef1a tr\u00ean ch\u1ec9 m\u1ee5c.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed ta c\u00f3 b\u1ea3ng d\u1eef li\u1ec7u employees nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>department<\/b><\/td>\n<td><b>age<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">30<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<td><span style=\"font-weight: 400;\">HR<\/span><\/td>\n<td><span style=\"font-weight: 400;\">25<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice Brown<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Marketing<\/span><\/td>\n<td><span style=\"font-weight: 400;\">28<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea1n ch\u1ea1y l\u1ec7nh sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT * FROM employees WHERE department = 'IT';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">MySQL ph\u1ea3i duy\u1ec7t qua to\u00e0n b\u1ed9 b\u1ea3ng \u0111\u1ec3 t\u00ecm c\u00e1c h\u00e0ng c\u00f3 <\/span><span style=\"font-weight: 400;\">department = &#8216;IT&#8217;<\/span><span style=\"font-weight: 400;\"> (full table scan), t\u1ee9c l\u00e0 ph\u1ea3i ki\u1ec3m tra t\u1eebng b\u1ea3n ghi trong b\u1ea3ng \u0111\u1ec3 t\u00ecm k\u1ebft qu\u1ea3 ph\u00f9 h\u1ee3p.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">N\u1ebfu ta t\u1ea1o ch\u1ec9 m\u1ee5c tr\u00ean c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">department<\/span><\/i><span style=\"font-weight: 400;\">:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE INDEX idx_department ON employees(department);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Khi \u0111\u00f3 n\u1ebfu ta ch\u1ea1y l\u1ea1i c\u00e2u l\u1ec7nh tr\u00ean, MySQL s\u1ebd s\u1eed d\u1ee5ng ch\u1ec9 m\u1ee5c <\/span><span style=\"font-weight: 400;\">idx_department<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 truy xu\u1ea5t nhanh c\u00e1c h\u00e0ng c\u00f3 <\/span><span style=\"font-weight: 400;\">department = &#8216;IT&#8217;<\/span><span style=\"font-weight: 400;\">, thay v\u00ec qu\u00e9t to\u00e0n b\u1ed9 b\u1ea3ng.<\/span><\/p>\n<h3><b>S\u1ef1 kh\u00e1c nhau gi\u1eefa MyISAM v\u00e0 InnoDB l\u00e0 g\u00ec?<\/b><\/h3>\n<p><b>MyISAM <\/b><span style=\"font-weight: 400;\">l\u00e0 Storage Engine m\u1eb7c \u0111\u1ecbnh trong c\u00e1c phi\u00ean b\u1ea3n MySQL c\u0169, \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c truy v\u1ea5n \u0111\u01a1n gi\u1ea3n, t\u1ed1c \u0111\u1ed9 cao v\u00e0 kh\u00f4ng y\u00eau c\u1ea7u c\u00e1c t\u00ednh n\u0103ng n\u00e2ng cao nh\u01b0 kh\u00f3a ngo\u1ea1i.<\/span><\/p>\n<p><b>InnoDB <\/b><span style=\"font-weight: 400;\">l\u00e0 Storage Engine hi\u1ec7n \u0111\u1ea1i v\u00e0 hi\u1ec7n t\u1ea1i c\u0169ng l\u00e0 engine m\u1eb7c \u0111\u1ecbnh trong MySQL. N\u00f3 h\u1ed7 tr\u1ee3 m\u1ed9t s\u1ed1 t\u00ednh n\u0103ng quan tr\u1ecdng nh\u01b0:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Giao d\u1ecbch (transactions): \u0110\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u th\u00f4ng qua c\u00e1c \u0111\u1eb7c t\u00ednh ACID (Atomicity, Consistency, Isolation, Durability).\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Kh\u00f3a ngo\u1ea1i (foreign key constraints): Duy tr\u00ec t\u00ednh to\u00e0n v\u1eb9n tham chi\u1ebfu gi\u1eefa c\u00e1c b\u1ea3ng.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">InnoDB l\u00e0 engine th\u00edch h\u1ee3p cho c\u00e1c \u1ee9ng d\u1ee5ng y\u00eau c\u1ea7u \u0111\u1ed9 tin c\u1eady v\u00e0 t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u cao.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">MyISAM v\u00e0 InnoDB c\u00f3 m\u1ed9t s\u1ed1 \u0111i\u1ec3m kh\u00e1c bi\u1ec7t nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>MyISAM<\/b><\/td>\n<td><b>InnoDB<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3 giao d\u1ecbch (Transactions)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng h\u1ed7 tr\u1ee3.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3 \u0111\u1ea7y \u0111\u1ee7 giao d\u1ecbch v\u1edbi c\u00e1c \u0111\u1eb7c t\u00ednh ACID (Atomicity, Consistency, Isolation, Durability).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Kh\u00f3a ngo\u1ea1i (Foreign Key)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng h\u1ed7 tr\u1ee3.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3, \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u gi\u1eefa c\u00e1c b\u1ea3ng.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">T\u1ed1c \u0111\u1ed9 \u0111\u1ecdc\/ghi<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ed1c \u0111\u1ed9 nhanh h\u01a1n khi ch\u1ec9 th\u1ef1c hi\u1ec7n \u0111\u1ecdc v\u00ec kh\u00f4ng c\u00f3 t\u00ednh n\u0103ng ph\u1ee9c t\u1ea1p nh\u01b0 kh\u00f3a ngo\u1ea1i hay giao d\u1ecbch.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1eadm h\u01a1n MyISAM trong m\u1ed9t s\u1ed1 tr\u01b0\u1eddng h\u1ee3p v\u00ec ph\u1ea3i qu\u1ea3n l\u00fd c\u00e1c t\u00ednh n\u0103ng n\u00e2ng cao.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Nh\u01b0ng s\u1ebd t\u1ed1t h\u01a1n khi c\u00f3 nhi\u1ec1u thao t\u00e1c \u0111\u1ecdc\/ghi \u0111\u1ed3ng th\u1eddi.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Kh\u00f3a b\u1ea3ng (Table Lock)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng kh\u00f3a to\u00e0n b\u1ea3ng (<\/span><i><span style=\"font-weight: 400;\">table-level locking<\/span><\/i><span style=\"font-weight: 400;\">), d\u1eabn \u0111\u1ebfn hi\u1ec7u n\u0103ng k\u00e9m khi c\u00f3 nhi\u1ec1u thao t\u00e1c th\u00eam\/x\u00f3a\/s\u1eeda \u0111\u1ed3ng th\u1eddi.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng kh\u00f3a d\u00f2ng (<\/span><i><span style=\"font-weight: 400;\">row-level locking<\/span><\/i><span style=\"font-weight: 400;\">), cho ph\u00e9p hi\u1ec7u n\u0103ng t\u1ed1t h\u01a1n khi ghi d\u1eef li\u1ec7u song song.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Kh\u00f4i ph\u1ee5c d\u1eef li\u1ec7u<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng h\u1ed7 tr\u1ee3 kh\u00f4i ph\u1ee5c d\u1eef li\u1ec7u sau l\u1ed7i h\u1ec7 th\u1ed1ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3 kh\u00f4i ph\u1ee5c t\u1ef1 \u0111\u1ed9ng sau l\u1ed7i nh\u1edd c\u01a1 ch\u1ebf <\/span><i><span style=\"font-weight: 400;\">redo log<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">T\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n cao (v\u00ec kh\u00f4ng c\u00f3 giao d\u1ecbch v\u00e0 kh\u00f3a ngo\u1ea1i).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n cao nh\u1edd h\u1ed7 tr\u1ee3 giao d\u1ecbch v\u00e0 kh\u00f3a ngo\u1ea1i.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">K\u00edch th\u01b0\u1edbc t\u1ec7p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1ec7p b\u1ea3ng nh\u1ecf h\u01a1n v\u00ec kh\u00f4ng c\u00f3 c\u00e1c t\u00ednh n\u0103ng giao d\u1ecbch.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">K\u00edch th\u01b0\u1edbc l\u1edbn h\u01a1n do l\u01b0u tr\u1eef th\u00eam metadata v\u00e0 th\u00f4ng tin giao d\u1ecbch.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng ph\u00f9 h\u1ee3p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u00f9 h\u1ee3p cho h\u1ec7 th\u1ed1ng \u0111\u1ecdc nhi\u1ec1u h\u01a1n ghi, nh\u01b0 c\u00e1c trang web t\u0129nh ho\u1eb7c h\u1ec7 th\u1ed1ng b\u00e1o c\u00e1o.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u00edch h\u1ee3p cho c\u00e1c \u1ee9ng d\u1ee5ng \u0111\u00f2i h\u1ecfi \u0111\u1ed9 tin c\u1eady cao, nh\u01b0 h\u1ec7 th\u1ed1ng t\u00e0i ch\u00ednh, th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 t\u1ea1o m\u1ed9t View trong MySQL?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">View trong MySQL l\u00e0 m\u1ed9t b\u1ea3ng \u1ea3o \u0111\u01b0\u1ee3c t\u1ea1o d\u1ef1a tr\u00ean k\u1ebft qu\u1ea3 c\u1ee7a m\u1ed9t c\u00e2u l\u1ec7nh truy v\u1ea5n SQL. View kh\u00f4ng l\u01b0u tr\u1eef d\u1eef li\u1ec7u th\u1ef1c t\u1ebf, m\u00e0 ch\u1ec9 l\u01b0u tr\u1eef \u0111\u1ecbnh ngh\u0129a c\u00e2u truy v\u1ea5n. Khi b\u1ea1n truy v\u1ea5n m\u1ed9t View, MySQL s\u1ebd ch\u1ea1y c\u00e2u truy v\u1ea5n g\u1ed1c v\u00e0 tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 nh\u01b0 m\u1ed9t b\u1ea3ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p t\u1ea1o view t\u1ed5ng qu\u00e1t:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE VIEW view_name AS<\/span>\r\n\r\n<span style=\"font-weight: 400;\">SELECT column1, column2, ...<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM table_name<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE condition;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed ta c\u00f3 b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees <\/span><\/i><span style=\"font-weight: 400;\">nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>department<\/b><\/td>\n<td><b>salary<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">5000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<td><span style=\"font-weight: 400;\">HR<\/span><\/td>\n<td><span style=\"font-weight: 400;\">6000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice Brown<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">7000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Bob Johnson<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Finance<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8000<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u1ea1o m\u1ed9t View <\/span><span style=\"font-weight: 400;\">high_salary_employees<\/span><span style=\"font-weight: 400;\"> hi\u1ec3n th\u1ecb nh\u00e2n vi\u00ean c\u00f3 l\u01b0\u01a1ng tr\u00ean 6000, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE VIEW high_salary_employees AS<\/span>\r\n\r\n<span style=\"font-weight: 400;\">SELECT name, department, salary<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE salary &gt; 6000;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Sau khi t\u1ea1o, ta c\u00f3 th\u1ec3 truy v\u1ea5n View gi\u1ed1ng nh\u01b0 m\u1ed9t b\u1ea3ng v\u1edbi c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT * FROM high_salary_employees;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ta \u0111\u01b0\u1ee3c k\u1ebft qu\u1ea3 nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>name<\/b><\/td>\n<td><b>department<\/b><\/td>\n<td><b>salary<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Alice Brown<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">7000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Bob Johnson<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Finance<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8000<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>\u1ee8ng d\u1ee5ng c\u1ee7a view trong MySQL l\u00e0 g\u00ec?<\/b><\/h3>\n<ul>\n<li><b>\u0110\u01a1n gi\u1ea3n h\u00f3a truy v\u1ea5n ph\u1ee9c t\u1ea1p: <\/b><span style=\"font-weight: 400;\">View gi\u00fap l\u01b0u tr\u1eef c\u00e1c truy v\u1ea5n ph\u1ee9c t\u1ea1p v\u00e0 s\u1eed d\u1ee5ng l\u1ea1i ch\u00fang nh\u01b0 m\u1ed9t b\u1ea3ng, gi\u1ea3m b\u1edbt vi\u1ec7c ph\u1ea3i vi\u1ebft l\u1ea1i c\u00e2u truy v\u1ea5n nhi\u1ec1u l\u1ea7n.<\/span><\/li>\n<li><b>T\u0103ng t\u00ednh b\u1ea3o m\u1eadt: <\/b><span style=\"font-weight: 400;\">View cho ph\u00e9p ki\u1ec3m so\u00e1t quy\u1ec1n truy c\u1eadp. B\u1ea1n c\u00f3 th\u1ec3 c\u1ea5p quy\u1ec1n cho ng\u01b0\u1eddi d\u00f9ng ch\u1ec9 tr\u00ean View thay v\u00ec b\u1ea3ng g\u1ed1c, \u1ea9n \u0111i c\u00e1c c\u1ed9t nh\u1ea1y c\u1ea3m.<\/span><\/li>\n<li><b>T\u0103ng t\u00ednh linh ho\u1ea1t trong qu\u1ea3n l\u00fd d\u1eef li\u1ec7u: <\/b><span style=\"font-weight: 400;\">View c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ed5ng h\u1ee3p d\u1eef li\u1ec7u t\u1eeb nhi\u1ec1u b\u1ea3ng kh\u00e1c nhau, gi\u00fap truy v\u1ea5n d\u1eef li\u1ec7u m\u1ed9t c\u00e1ch d\u1ec5 d\u00e0ng v\u00e0 nh\u1ea5t qu\u00e1n.<\/span><\/li>\n<li><b>\u0110\u1ea3m b\u1ea3o t\u00ednh nh\u1ea5t qu\u00e1n c\u1ee7a d\u1eef li\u1ec7u: <\/b><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng View \u0111\u1ec3 chu\u1ea9n h\u00f3a c\u00e1c truy v\u1ea5n v\u00e0 d\u1eef li\u1ec7u hi\u1ec3n th\u1ecb, gi\u00fap c\u00e1c truy v\u1ea5n ph\u1ee9c t\u1ea1p tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u ch\u00ednh x\u00e1c h\u01a1n.<\/span><\/li>\n<li><b>H\u1ed7 tr\u1ee3 ph\u00e2n t\u00edch d\u1eef li\u1ec7u: <\/b><span style=\"font-weight: 400;\">View h\u1eefu \u00edch trong c\u00e1c b\u00e1o c\u00e1o, n\u01a1i d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c l\u1ecdc ho\u1eb7c t\u1ed5ng h\u1ee3p theo c\u00e1c \u0111i\u1ec1u ki\u1ec7n c\u1ee5 th\u1ec3.<\/span><\/li>\n<\/ul>\n<p><b>M\u1ed9t s\u1ed1 l\u01b0u \u00fd khi s\u1eed d\u1ee5ng View:<\/b><\/p>\n<ul>\n<li><b>Hi\u1ec7u su\u1ea5t: <\/b><span style=\"font-weight: 400;\">V\u00ec View kh\u00f4ng l\u01b0u tr\u1eef d\u1eef li\u1ec7u, m\u1ed7i l\u1ea7n truy v\u1ea5n View, MySQL ph\u1ea3i th\u1ef1c thi l\u1ea1i c\u00e2u truy v\u1ea5n g\u1ed1c, d\u1eabn \u0111\u1ebfn \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn hi\u1ec7u su\u1ea5t n\u1ebfu c\u00e2u truy v\u1ea5n g\u1ed1c ph\u1ee9c t\u1ea1p.<\/span><\/li>\n<li><b>Gi\u1edbi h\u1ea1n c\u1eadp nh\u1eadt: <\/b><span style=\"font-weight: 400;\">Kh\u00f4ng ph\u1ea3i View n\u00e0o c\u0169ng c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt. C\u00e1c View ph\u1ee9c t\u1ea1p (d\u00f9ng h\u00e0m t\u1ed5ng h\u1ee3p, GROUP BY, JOIN) th\u01b0\u1eddng ch\u1ec9 cho ph\u00e9p \u0111\u1ecdc d\u1eef li\u1ec7u.<\/span><\/li>\n<li><b>Qu\u1ea3n l\u00fd thay \u0111\u1ed5i: <\/b><span style=\"font-weight: 400;\">N\u1ebfu c\u1ea5u tr\u00fac b\u1ea3ng g\u1ed1c thay \u0111\u1ed5i (x\u00f3a ho\u1eb7c \u0111\u1ed5i t\u00ean c\u1ed9t), View li\u00ean quan c\u00f3 th\u1ec3 b\u1ecb l\u1ed7i v\u00e0 c\u1ea7n \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt l\u1ea1i.<\/span><\/li>\n<\/ul>\n<h3><b>Triggers trong MySQL l\u00e0 g\u00ec? L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 t\u1ea1o m\u1ed9t Trigger?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trigger trong MySQL l\u00e0 m\u1ed9t <\/span><b>th\u1ee7 t\u1ee5c l\u01b0u tr\u1eef \u0111\u1eb7c bi\u1ec7t<\/b><span style=\"font-weight: 400;\"> t\u1ef1 \u0111\u1ed9ng th\u1ef1c thi khi c\u00f3 m\u1ed9t s\u1ef1 ki\u1ec7n c\u1ee5 th\u1ec3 x\u1ea3y ra tr\u00ean m\u1ed9t b\u1ea3ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. Trigger \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u1eed l\u00fd t\u1ef1 \u0111\u1ed9ng c\u00e1c t\u00e1c v\u1ee5 nh\u01b0 ki\u1ec3m tra t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u, ghi log, ho\u1eb7c th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c kh\u00e1c tr\u01b0\u1edbc ho\u1eb7c sau khi th\u1ef1c hi\u1ec7n c\u00e1c c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">UPDATE<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p t\u1ea1o Trigger:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TRIGGER trigger_name<\/span>\r\n\r\n<span style=\"font-weight: 400;\">{BEFORE | AFTER} {INSERT | UPDATE | DELETE}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON table_name<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FOR EACH ROW<\/span>\r\n\r\n<span style=\"font-weight: 400;\">BEGIN<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0-- SQL code to execute<\/span>\r\n\r\n<span style=\"font-weight: 400;\">END;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">BEFORE<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">AFTER<\/span><span style=\"font-weight: 400;\">: X\u00e1c \u0111\u1ecbnh th\u1eddi \u0111i\u1ec3m th\u1ef1c thi Trigger (tr\u01b0\u1edbc ho\u1eb7c sau s\u1ef1 ki\u1ec7n).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">INSERT | UPDATE | DELETE<\/span><span style=\"font-weight: 400;\">: X\u00e1c \u0111\u1ecbnh lo\u1ea1i s\u1ef1 ki\u1ec7n k\u00edch ho\u1ea1t Trigger.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">table_name<\/span><span style=\"font-weight: 400;\">: B\u1ea3ng m\u00e0 Trigger g\u1eafn li\u1ec1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">FOR EACH ROW<\/span><span style=\"font-weight: 400;\">: X\u00e1c \u0111\u1ecbnh Trigger s\u1ebd \u00e1p d\u1ee5ng cho t\u1eebng h\u00e0ng \u0111\u01b0\u1ee3c t\u00e1c \u0111\u1ed9ng b\u1edfi s\u1ef1 ki\u1ec7n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>SQL code:<\/b><span style=\"font-weight: 400;\"> l\u00e0 \u0111o\u1ea1n m\u00e3 SQL s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi khi Trigger \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: gi\u1ea3 s\u1eed ta c\u00f3 b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 mu\u1ed1n l\u01b0u log m\u1ed7i khi c\u00f3 b\u1ea3n ghi m\u1edbi \u0111\u01b0\u1ee3c ch\u00e8n v\u00e0o b\u1ea3ng n\u00e0y, ta c\u00f3 th\u1ec3 t\u1ea1o Trigger nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE TRIGGER after_employee_insert<\/span>\r\n\r\n<span style=\"font-weight: 400;\">AFTER INSERT<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FOR EACH ROW<\/span>\r\n\r\n<span style=\"font-weight: 400;\">BEGIN<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0INSERT INTO employee_logs (log_message)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0VALUES (CONCAT('New employee added: ', NEW.name));<\/span>\r\n\r\n<span style=\"font-weight: 400;\">END;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">AFTER INSERT<\/span><span style=\"font-weight: 400;\">: Trigger \u0111\u01b0\u1ee3c th\u1ef1c thi sau khi ch\u00e8n d\u1eef li\u1ec7u v\u00e0o b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">NEW<\/span><span style=\"font-weight: 400;\">: L\u00e0 t\u1eeb kh\u00f3a \u0111\u1ea1i di\u1ec7n cho d\u1eef li\u1ec7u m\u1edbi \u0111\u01b0\u1ee3c ch\u00e8n v\u00e0o.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">CONCAT<\/span><span style=\"font-weight: 400;\">: K\u1ebft h\u1ee3p chu\u1ed7i \u0111\u1ec3 t\u1ea1o th\u00f4ng b\u00e1o log.<\/span><\/li>\n<\/ul>\n<h4><b>L\u01b0u \u00fd khi s\u1eed d\u1ee5ng Trigger<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">M\u1eb7c d\u00f9 Trigger gi\u00fap g\u00f3p ph\u1ea7n \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u v\u00e0 th\u1ef1c hi\u1ec7n c\u00e1c t\u00e1c v\u1ee5 t\u1ef1 \u0111\u1ed9ng, gi\u00fap gi\u1ea3m thi\u1ec3u l\u1ed7i th\u1ee7 c\u00f4ng v\u00e0 t\u0103ng t\u00ednh t\u1ef1 \u0111\u1ed9ng h\u00f3a nh\u01b0ng khi s\u1eed d\u1ee5ng trigger c\u1ea7n l\u01b0u \u00fd m\u1ed9t s\u1ed1 v\u1ea5n \u0111\u1ec1 nh\u01b0:<\/span><\/p>\n<ul>\n<li><b>Hi\u1ec7u su\u1ea5t: <\/b><span style=\"font-weight: 400;\">Trigger c\u00f3 th\u1ec3 l\u00e0m gi\u1ea3m hi\u1ec7u su\u1ea5t n\u1ebfu s\u1eed d\u1ee5ng c\u00e1c truy v\u1ea5n ph\u1ee9c t\u1ea1p ho\u1eb7c t\u00ednh to\u00e1n l\u1edbn.<\/span><\/li>\n<li><b>Kh\u00f4ng t\u01b0\u01a1ng t\u00e1c tr\u1ef1c ti\u1ebfp: <\/b><span style=\"font-weight: 400;\">Trigger kh\u00f4ng th\u1ec3 g\u1ecdi tr\u1ef1c ti\u1ebfp t\u1eeb c\u00e2u l\u1ec7nh SQL m\u00e0 ch\u1ec9 k\u00edch ho\u1ea1t khi c\u00f3 s\u1ef1 ki\u1ec7n x\u1ea3y ra.<\/span><\/li>\n<\/ul>\n<h4><b>Gi\u1edbi h\u1ea1n trong Trigger:<\/b><\/h4>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Trigger kh\u00f4ng h\u1ed7 tr\u1ee3 s\u1eed d\u1ee5ng to\u00e0n b\u1ed9 c\u00e1c l\u1ec7nh SQL (nh\u01b0 <\/span><span style=\"font-weight: 400;\">COMMIT<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">ROLLBACK<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Trigger kh\u00f4ng th\u1ec3 tr\u1ef1c ti\u1ebfp g\u1ecdi m\u1ed9t Trigger kh\u00e1c (tr\u00e1nh v\u00f2ng l\u1eb7p v\u00f4 h\u1ea1n).<\/span><\/li>\n<\/ul>\n<h3><b>Stored Procedures v\u00e0 Functions kh\u00e1c nhau nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>Stored Procedures<\/b><\/td>\n<td><b>Functions<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u0110\u1ecbnh ngh\u0129a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1ed9t t\u1eadp h\u1ee3p c\u00e1c c\u00e2u l\u1ec7nh SQL \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef trong c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u1ec3 th\u1ef1c thi nhi\u1ec1u thao t\u00e1c.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1ed9t t\u1eadp h\u1ee3p c\u00e1c c\u00e2u l\u1ec7nh SQL \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef \u0111\u1ec3 th\u1ef1c hi\u1ec7n m\u1ed9t t\u00e1c v\u1ee5 c\u1ee5 th\u1ec3 v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Output<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng b\u1eaft bu\u1ed9c ph\u1ea3i tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb, nh\u01b0ng c\u00f3 th\u1ec3 tr\u1ea3 v\u1ec1 th\u00f4ng qua tham s\u1ed1 \u0111\u1ea7u ra (<\/span><span style=\"font-weight: 400;\">OUT<\/span><span style=\"font-weight: 400;\"> parameter).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lu\u00f4n tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb duy nh\u1ea5t.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00e1ch g\u1ecdi<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u01b0\u1ee3c g\u1ecdi b\u1eb1ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">CALL<\/span><span style=\"font-weight: 400;\">.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u01b0\u1ee3c g\u1ecdi tr\u1ef1c ti\u1ebfp trong c\u00e1c c\u00e2u l\u1ec7nh SQL nh\u01b0 <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c trong c\u00e1c bi\u1ec3u th\u1ee9c.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng trong c\u00e2u l\u1ec7nh SQL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng th\u1ec3 s\u1eed d\u1ee5ng tr\u1ef1c ti\u1ebfp trong c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\">.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 s\u1eed d\u1ee5ng tr\u1ef1c ti\u1ebfp trong c\u00e2u l\u1ec7nh SQL nh\u01b0 <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\">, ORDER BY ho\u1eb7c <\/span><span style=\"font-weight: 400;\">JOIN<\/span><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Tham s\u1ed1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3 tham s\u1ed1 \u0111\u1ea7u v\u00e0o (<\/span><span style=\"font-weight: 400;\">IN<\/span><span style=\"font-weight: 400;\">), \u0111\u1ea7u ra (<\/span><span style=\"font-weight: 400;\">OUT<\/span><span style=\"font-weight: 400;\">) v\u00e0 c\u1ea3 \u0111\u1ea7u v\u00e0o\/\u0111\u1ea7u ra (<\/span><span style=\"font-weight: 400;\">INOUT<\/span><span style=\"font-weight: 400;\">).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1ec9 h\u1ed7 tr\u1ee3 tham s\u1ed1 \u0111\u1ea7u v\u00e0o (<\/span><span style=\"font-weight: 400;\">IN<\/span><span style=\"font-weight: 400;\">).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">M\u1ee5c \u0111\u00edch<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c t\u00e1c v\u1ee5 ph\u1ee9c t\u1ea1p ho\u1eb7c thao t\u00e1c tr\u00ean d\u1eef li\u1ec7u.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c t\u00ednh to\u00e1n ho\u1eb7c tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 d\u1ef1a tr\u00ean \u0111\u1ea7u v\u00e0o.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">G\u1ecdi nhi\u1ec1u l\u1ea7n trong truy v\u1ea5n<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng ph\u00f9 h\u1ee3p \u0111\u1ec3 g\u1ecdi l\u1eb7p l\u1ea1i trong m\u1ed9t truy v\u1ea5n v\u00ec kh\u00f4ng th\u1ec3 s\u1eed d\u1ee5ng trong bi\u1ec3u th\u1ee9c.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u00f9 h\u1ee3p \u0111\u1ec3 g\u1ecdi nhi\u1ec1u l\u1ea7n trong m\u1ed9t truy v\u1ea5n (v\u00ed d\u1ee5: s\u1eed d\u1ee5ng trong c\u1ed9t t\u00ednh to\u00e1n).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u0110\u1ed9 ph\u1ee9c t\u1ea1p<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 bao g\u1ed3m nhi\u1ec1u c\u00e2u l\u1ec7nh SQL, v\u00f2ng l\u1eb7p, \u0111i\u1ec1u ki\u1ec7n, v\u00e0 c\u00e1c th\u1ee7 t\u1ee5c kh\u00e1c.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u01a1n gi\u1ea3n h\u01a1n, t\u1eadp trung v\u00e0o t\u00ednh to\u00e1n v\u00e0 tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3 giao d\u1ecbch<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c l\u1ec7nh nh\u01b0 <\/span><span style=\"font-weight: 400;\">COMMIT<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">ROLLBACK<\/span><span style=\"font-weight: 400;\">.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng h\u1ed7 tr\u1ee3 giao d\u1ecbch nh\u01b0 <\/span><span style=\"font-weight: 400;\">COMMIT<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">ROLLBACK<\/span><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hi\u1ec7u su\u1ea5t<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u00f9 h\u1ee3p v\u1edbi c\u00e1c thao t\u00e1c d\u1eef li\u1ec7u l\u1edbn ho\u1eb7c logic ph\u1ee9c t\u1ea1p.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u00f9 h\u1ee3p cho c\u00e1c ph\u00e9p t\u00ednh to\u00e1n ho\u1eb7c x\u1eed l\u00fd d\u1eef li\u1ec7u nh\u1ecf.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng<\/span><\/td>\n<td><span style=\"font-weight: 400;\">X\u1eed l\u00fd logic ph\u1ee9c t\u1ea1p: th\u00eam, s\u1eeda, ho\u1eb7c x\u00f3a d\u1eef li\u1ec7u trong b\u1ea3ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u00ednh to\u00e1n: t\u00ednh t\u1ed5ng, tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 t\u1eeb c\u00e1c c\u1ed9t ho\u1eb7c gi\u00e1 tr\u1ecb.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Subquery l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Subquery (truy v\u1ea5n con) trong MySQL l\u00e0 m\u1ed9t c\u00e2u truy v\u1ea5n SQL l\u1ed3ng b\u00ean trong m\u1ed9t c\u00e2u truy v\u1ea5n kh\u00e1c v\u00e0 th\u01b0\u1eddng \u0111\u01b0\u1ee3c bao trong d\u1ea5u ngo\u1eb7c \u0111\u01a1n (). Subquery \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u m\u00e0 c\u00e2u truy v\u1ea5n b\u00ean ngo\u00e0i s\u1ebd s\u1eed d\u1ee5ng \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c t\u00e1c v\u1ee5 kh\u00e1c. Subquery th\u01b0\u1eddng xu\u1ea5t hi\u1ec7n trong c\u00e1c m\u1ec7nh \u0111\u1ec1 nh\u01b0 <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">FROM<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">HAVING<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 c\u00fa ph\u00e1p Subquery trong m\u1ec7nh \u0111\u1ec1 Where:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT column1, column2, ...\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM table_name\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE column_name operator (SELECT column_name FROM another_table WHERE condition);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed ta c\u00f3 2 b\u1ea3ng:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">B\u1ea3ng employees:<\/span><\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>department_id<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">101<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<td><span style=\"font-weight: 400;\">102<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice Brown<\/span><\/td>\n<td><span style=\"font-weight: 400;\">101<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li><span style=\"font-weight: 400;\">B\u1ea3ng Departments:<\/span><\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">101<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">102<\/span><\/td>\n<td><span style=\"font-weight: 400;\">HR<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">103<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Marketing<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u00ecm nh\u00e2n vi\u00ean thu\u1ed9c ph\u00f2ng IT, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>C\u00e1ch 1:<\/strong> S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">IN<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT name\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE department_id IN (SELECT id FROM Departments WHERE name = 'IT');<\/span><\/pre>\n<p><span style=\"font-weight: 400;\"><strong>C\u00e1ch 2:<\/strong> Th\u00eam <\/span><span style=\"font-weight: 400;\">LIMIT 1<\/span><span style=\"font-weight: 400;\"> v\u00e0o subquery<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT name\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE department_id = (SELECT id FROM Departments WHERE name = 'IT' LIMIT 1);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">To\u00e1n t\u1eed <\/span><span style=\"font-weight: 400;\">IN<\/span><span style=\"font-weight: 400;\">: Ph\u00f9 h\u1ee3p khi subquery c\u00f3 th\u1ec3 tr\u1ea3 v\u1ec1 nhi\u1ec1u gi\u00e1 tr\u1ecb. L\u1ef1a ch\u1ecdn n\u00e0y an to\u00e0n v\u00e0 ch\u00ednh x\u00e1c h\u01a1n khi c\u00f3 kh\u1ea3 n\u0103ng nhi\u1ec1u ph\u00f2ng ban c\u00f9ng t\u00ean &#8220;IT&#8221;.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">LIMIT 1<\/span><span style=\"font-weight: 400;\">: S\u1eed d\u1ee5ng trong tr\u01b0\u1eddng h\u1ee3p ch\u1eafc ch\u1eafn ch\u1ec9 c\u1ea7n l\u1ea5y m\u1ed9t gi\u00e1 tr\u1ecb \u0111\u1ea7u ti\u00ean t\u1eeb subquery, \u0111i\u1ec1u n\u00e0y s\u1ebd tr\u00e1nh l\u1ed7i khi subquery tr\u1ea3 v\u1ec1 nhi\u1ec1u gi\u00e1 tr\u1ecb.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cac_cau_hoi_phong_van_MySQL_danh_cho_Advanced\"><\/span><b>C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL d\u00e0nh cho Advanced<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>Replication trong MySQL ho\u1ea1t \u0111\u1ed9ng nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Replication trong MySQL l\u00e0 qu\u00e1 tr\u00ecnh sao ch\u00e9p d\u1eef li\u1ec7u t\u1eeb m\u1ed9t m\u00e1y ch\u1ee7 c\u01a1 s\u1edf d\u1eef li\u1ec7u (Master) sang m\u1ed9t ho\u1eb7c nhi\u1ec1u m\u00e1y ch\u1ee7 kh\u00e1c (Slave). Replication gi\u00fap c\u1ea3i thi\u1ec7n t\u00ednh s\u1eb5n s\u00e0ng (availability), kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng (scalability), v\u00e0 kh\u1ea3 n\u0103ng sao l\u01b0u (backup) c\u1ee7a c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/p>\n<h4><b>C\u00e1c th\u00e0nh ph\u1ea7n ch\u00ednh trong Replication<\/b><\/h4>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Primary (Master)<\/b><span style=\"font-weight: 400;\">: M\u00e1y ch\u1ee7 ch\u00ednh, n\u01a1i c\u00e1c thay \u0111\u1ed5i d\u1eef li\u1ec7u (INSERT, UPDATE, DELETE) \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n v\u00e0 ghi l\u1ea1i trong Binary Log.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Replica (Slave):<\/b><span style=\"font-weight: 400;\"> M\u00e1y ch\u1ee7 ph\u1ee5, sao ch\u00e9p d\u1eef li\u1ec7u t\u1eeb Primary th\u00f4ng qua c\u00e1c nh\u1eadt k\u00fd v\u00e0 th\u1ef1c hi\u1ec7n l\u1ea1i c\u00e1c thay \u0111\u1ed5i \u0111\u1ec3 \u0111\u1ed3ng b\u1ed9 h\u00f3a d\u1eef li\u1ec7u.<\/span><\/li>\n<\/ul>\n<h4><b>C\u00e1ch ho\u1ea1t \u0111\u1ed9ng c\u1ee7a Replication trong MySQL<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Replication trong MySQL ho\u1ea1t \u0111\u1ed9ng d\u1ef1a tr\u00ean m\u00f4 h\u00ecnh Master-Slave, theo c\u00e1c b\u01b0\u1edbc sau:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ghi nh\u1eadt k\u00fd giao d\u1ecbch tr\u00ean Master (Binary Log): <\/b><span style=\"font-weight: 400;\">Khi d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c ch\u00e8n, c\u1eadp nh\u1eadt, ho\u1eb7c x\u00f3a tr\u00ean m\u00e1y ch\u1ee7 Master, c\u00e1c thay \u0111\u1ed5i n\u00e0y s\u1ebd \u0111\u01b0\u1ee3c ghi v\u00e0o Binary Log (t\u1ec7p nh\u1eadt k\u00fd nh\u1ecb ph\u00e2n). Binary Log ch\u1ee9a th\u00f4ng tin v\u1ec1 c\u00e1c thay \u0111\u1ed5i \u1edf d\u1ea1ng s\u1ef1 ki\u1ec7n (event).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Sao ch\u00e9p nh\u1eadt k\u00fd giao d\u1ecbch t\u1eeb Master \u0111\u1ebfn Slave: <\/b><span style=\"font-weight: 400;\">M\u00e1y ch\u1ee7 Slave k\u1ebft n\u1ed1i v\u1edbi Master v\u00e0 sao ch\u00e9p d\u1eef li\u1ec7u trong Binary Log th\u00f4ng qua hai lu\u1ed3ng: I\/O Thread v\u00e0 SQL Thread.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u00c1p d\u1ee5ng c\u00e1c thay \u0111\u1ed5i tr\u00ean Slave<\/b><span style=\"font-weight: 400;\">: M\u00e1y ch\u1ee7 Replica kh\u00f4ng \u0111\u1ecdc tr\u1ef1c ti\u1ebfp t\u1eeb Binary Log. Thay v\u00e0o \u0111\u00f3, sau khi c\u00e1c s\u1ef1 ki\u1ec7n \u0111\u01b0\u1ee3c sao ch\u00e9p t\u1eeb Binary Log v\u1ec1 Relay Log, Replica s\u1ebd \u0111\u1ecdc n\u1ed9i dung t\u1eeb Relay Log v\u00e0 th\u1ef1c hi\u1ec7n l\u1ea1i c\u00e1c thay \u0111\u1ed5i tr\u00ean c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u1ee7a n\u00f3.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u0110\u1ed3ng b\u1ed9 h\u00f3a d\u1eef li\u1ec7u: <\/b><span style=\"font-weight: 400;\">Qu\u00e1 tr\u00ecnh sao ch\u00e9p di\u1ec5n ra g\u1ea7n nh\u01b0 li\u00ean t\u1ee5c, \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u tr\u00ean Slave lu\u00f4n ph\u1ea3n \u00e1nh c\u00e1c thay \u0111\u1ed5i m\u1edbi nh\u1ea5t tr\u00ean Master.<\/span><\/li>\n<\/ol>\n<h3><b>Chu\u1ea9n h\u00f3a l\u00e0 g\u00ec?\u00a0<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Chu\u1ea9n h\u00f3a (Normalization) trong c\u01a1 s\u1edf d\u1eef li\u1ec7u l\u00e0 m\u1ed9t qu\u00e1 tr\u00ecnh t\u1ed5 ch\u1ee9c d\u1eef li\u1ec7u trong c\u00e1c b\u1ea3ng \u0111\u1ec3 gi\u1ea3m thi\u1ec3u s\u1ef1 d\u01b0 th\u1eeba (redundancy) v\u00e0 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ee5c ti\u00eau c\u1ee7a chu\u1ea9n h\u00f3a l\u00e0 t\u1ed5 ch\u1ee9c d\u1eef li\u1ec7u h\u1ee3p l\u00fd \u0111\u1ec3 tr\u00e1nh d\u01b0 th\u1eeba v\u00e0 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n, th\u01b0\u1eddng l\u00e0 ph\u00e2n t\u00e1ch d\u1eef li\u1ec7u th\u00e0nh c\u00e1c b\u1ea3ng nh\u1ecf h\u01a1n, v\u1edbi m\u1ed7i b\u1ea3ng t\u1eadp trung v\u00e0o m\u1ed9t kh\u00eda c\u1ea1nh c\u1ee5 th\u1ec3, \u0111\u1ed3ng th\u1eddi duy tr\u00ec m\u1ed1i quan h\u1ec7 logic gi\u1eefa c\u00e1c b\u1ea3ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Chu\u1ea9n ho\u00e1 c\u00f3 nh\u1eefng lo\u1ea1i sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>D\u1ea1ng Chu\u1ea9n ho\u00e1<\/b><\/td>\n<td><b>Y\u00eau c\u1ea7u Ch\u00ednh<\/b><\/td>\n<td><b>M\u1ee5c Ti\u00eau<\/b><\/td>\n<td><b>V\u00ed D\u1ee5<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1NF<\/b><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; Kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb l\u1eb7p ho\u1eb7c m\u1ea3ng trong c\u00e1c c\u1ed9t.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; M\u1ed7i c\u1ed9t ch\u1ec9 ch\u1ee9a m\u1ed9t gi\u00e1 tr\u1ecb duy nh\u1ea5t tr\u00ean m\u1ed7i h\u00e0ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ea3m b\u1ea3o c\u1ea5u tr\u00fac c\u01a1 b\u1ea3n c\u1ee7a b\u1ea3ng, d\u1eef li\u1ec7u c\u00f3 t\u1ed5 ch\u1ee9c r\u00f5 r\u00e0ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">B\u1ea3ng l\u01b0u s\u1ed1 \u0111i\u1ec7n tho\u1ea1i: N\u1ebfu m\u1ed9t c\u1ed9t ch\u1ee9a danh s\u00e1ch s\u1ed1 \u0111i\u1ec7n tho\u1ea1i 1234567890, 0987654321, c\u1ea7n t\u00e1ch th\u00e0nh c\u00e1c h\u00e0ng ri\u00eang bi\u1ec7t.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>2NF<\/b><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; \u0110\u00e1p \u1ee9ng 1NF.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u00f4ng c\u00f3 ph\u1ee5 thu\u1ed9c m\u1ed9t ph\u1ea7n v\u00e0o kh\u00f3a ch\u00ednh.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lo\u1ea1i b\u1ecf d\u01b0 th\u1eeba do ph\u1ee5 thu\u1ed9c m\u1ed9t ph\u1ea7n, t\u1eadp trung v\u00e0o kh\u00f3a ch\u00ednh.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea3ng ch\u1ee9a <\/span><i><span style=\"font-weight: 400;\">student_id<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">course_id<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 <\/span><i><span style=\"font-weight: 400;\">student_name <\/span><\/i><span style=\"font-weight: 400;\">(gi\u1ea3 s\u1eed <\/span><i><span style=\"font-weight: 400;\">student_id<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">course_id <\/span><\/i><span style=\"font-weight: 400;\">l\u00e0 kh\u00f3a ch\u00ednh), th\u00ec <\/span><i><span style=\"font-weight: 400;\">student_name<\/span><\/i><span style=\"font-weight: 400;\"> n\u00ean \u0111\u01b0\u1ee3c t\u00e1ch ra b\u1ea3ng ri\u00eang v\u00ec n\u00f3 ph\u1ee5 thu\u1ed9c v\u00e0o <\/span><i><span style=\"font-weight: 400;\">student_id<\/span><\/i><span style=\"font-weight: 400;\">, kh\u00f4ng ph\u1ee5 thu\u1ed9c <\/span><i><span style=\"font-weight: 400;\">course_id<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>3NF<\/b><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; \u0110\u00e1p \u1ee9ng 2NF.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u00f4ng c\u00f3 ph\u1ee5 thu\u1ed9c b\u1eafc c\u1ea7u gi\u1eefa c\u00e1c c\u1ed9t kh\u00f4ng ph\u1ea3i l\u00e0\u00a0 kh\u00f3a.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lo\u1ea1i b\u1ecf ph\u1ee5 thu\u1ed9c b\u1eafc c\u1ea7u \u0111\u1ec3 t\u0103ng t\u00ednh to\u00e0n v\u1eb9n v\u00e0 logic d\u1eef li\u1ec7u.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea3ng ch\u1ee9a <\/span><i><span style=\"font-weight: 400;\">student_id<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">course_id<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 <\/span><i><span style=\"font-weight: 400;\">department_name<\/span><\/i><span style=\"font-weight: 400;\">, th\u00ec <\/span><i><span style=\"font-weight: 400;\">department_name<\/span><\/i><span style=\"font-weight: 400;\"> n\u00ean t\u00e1ch ra b\u1ea3ng kh\u00e1c n\u1ebfu n\u00f3 ch\u1ec9 ph\u1ee5 thu\u1ed9c v\u00e0o <\/span><i><span style=\"font-weight: 400;\">course_id<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>BCNF<\/b><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; \u0110\u00e1p \u1ee9ng 3NF.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; M\u1ecdi ph\u1ee5 thu\u1ed9c h\u00e0m (functional dependency) ph\u1ea3i li\u00ean quan \u0111\u1ebfn Candidate Key.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">X\u1eed l\u00fd c\u00e1c ph\u1ee5 thu\u1ed9c ph\u1ee9c t\u1ea1p h\u01a1n so v\u1edbi 3NF.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea3ng ch\u1ee9a <\/span><i><span style=\"font-weight: 400;\">employee_id<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">department_id<\/span><\/i><span style=\"font-weight: 400;\">, v\u00e0 <\/span><i><span style=\"font-weight: 400;\">manager_id<\/span><\/i><span style=\"font-weight: 400;\"> trong \u0111\u00f3 <\/span><i><span style=\"font-weight: 400;\">manager_id<\/span><\/i><span style=\"font-weight: 400;\"> ph\u1ee5 thu\u1ed9c v\u00e0o <\/span><i><span style=\"font-weight: 400;\">department_id<\/span><\/i><span style=\"font-weight: 400;\">, c\u1ea7n t\u00e1ch <\/span><i><span style=\"font-weight: 400;\">manager_id<\/span><\/i><span style=\"font-weight: 400;\"> ra th\u00e0nh b\u1ea3ng ri\u00eang.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>4NF<\/b><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; \u0110\u00e1p \u1ee9ng BCNF.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Kh\u00f4ng c\u00f3 ph\u1ee5 thu\u1ed9c \u0111a tr\u1ecb (multivalued dependency).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lo\u1ea1i b\u1ecf m\u1ed1i quan h\u1ec7 \u0111a tr\u1ecb gi\u1eefa c\u00e1c c\u1ed9t.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea3ng l\u01b0u th\u00f4ng tin nh\u00e2n vi\u00ean v\u00e0 c\u00e1c d\u1ef1 \u00e1n h\u1ecd tham gia, c\u00f9ng v\u1edbi k\u1ef9 n\u0103ng c\u1ee7a h\u1ecd, n\u00ean t\u00e1ch th\u00e0nh 2 b\u1ea3ng ri\u00eang: m\u1ed9t cho d\u1ef1 \u00e1n v\u00e0 m\u1ed9t cho k\u1ef9 n\u0103ng.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>5NF<\/b><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; \u0110\u00e1p \u1ee9ng 4NF.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Lo\u1ea1i b\u1ecf ph\u1ee5 thu\u1ed9c k\u1ebft h\u1ee3p (join dependency).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u00e1nh d\u01b0 th\u1eeba do c\u00e1c b\u1ea3ng k\u1ebft h\u1ee3p ph\u1ee9c t\u1ea1p.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">B\u1ea3ng l\u01b0u m\u1ed1i quan h\u1ec7 gi\u1eefa kh\u00e1ch h\u00e0ng, s\u1ea3n ph\u1ea9m, v\u00e0 nh\u00e2n vi\u00ean b\u00e1n h\u00e0ng c\u1ea7n \u0111\u01b0\u1ee3c t\u00e1ch th\u00e0nh c\u00e1c b\u1ea3ng nh\u1ecf h\u01a1n \u0111\u1ec3 tr\u00e1nh d\u01b0 th\u1eeba trong c\u00e1c k\u1ebft h\u1ee3p ba chi\u1ec1u.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>6NF<\/b><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; D\u1eef li\u1ec7u \u0111\u01b0\u1ee3c ph\u00e2n t\u00e1ch ho\u00e0n to\u00e0n, kh\u00f4ng c\u00f2n d\u01b0 th\u1eeba n\u00e0o t\u1ed3n t\u1ea1i d\u1ef1a tr\u00ean ph\u1ee5 thu\u1ed9c h\u00e0m th\u1eddi gian trong c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 ph\u00e2n t\u00e1n.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211; Th\u01b0\u1eddng \u00e1p d\u1ee5ng cho c\u01a1 s\u1edf d\u1eef li\u1ec7u ph\u00e2n t\u00e1n.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ea3m b\u1ea3o t\u1ed1i \u01b0u h\u00f3a d\u1eef li\u1ec7u trong h\u1ec7 th\u1ed1ng linh ho\u1ea1t cao.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u01b0\u1eddng \u00e1p d\u1ee5ng cho c\u00e1c kho d\u1eef li\u1ec7u l\u1edbn. V\u00ed d\u1ee5, chia b\u1ea3ng giao d\u1ecbch th\u00e0nh c\u00e1c b\u1ea3ng l\u01b0u ri\u00eang t\u1eebng y\u1ebfu t\u1ed1 nh\u01b0 kh\u00e1ch h\u00e0ng, s\u1ea3n ph\u1ea9m, v\u00e0 ng\u00e0y giao d\u1ecbch \u0111\u1ec3 t\u1ed1i \u01b0u h\u00f3a.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Clustered index v\u00e0 non clustered index l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trong c\u01a1 s\u1edf d\u1eef li\u1ec7u, Index (ch\u1ec9 m\u1ee5c) l\u00e0 m\u1ed9t c\u1ea5u tr\u00fac d\u1eef li\u1ec7u gi\u00fap t\u0103ng t\u1ed1c \u0111\u1ed9 truy v\u1ea5n v\u00e0 thao t\u00e1c v\u1edbi b\u1ea3ng. Trong \u0111\u00f3, c\u00f3 hai lo\u1ea1i ch\u1ec9 m\u1ee5c ph\u1ed5 bi\u1ebfn: Clustered Index v\u00e0 Non-Clustered Index.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>Clustered Index<\/b><\/td>\n<td><b>Non-Clustered Index<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u0110\u1ecbnh ngh\u0129a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0 ch\u1ec9 m\u1ee5c m\u00e0 d\u1eef li\u1ec7u v\u1eadt l\u00fd trong b\u1ea3ng \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp theo th\u1ee9 t\u1ef1 c\u1ee7a ch\u1ec9 m\u1ee5c.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0 ch\u1ec9 m\u1ee5c m\u00e0 d\u1eef li\u1ec7u v\u1eadt l\u00fd trong b\u1ea3ng kh\u00f4ng \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp theo ch\u1ec9 m\u1ee5c, ch\u1ec9 l\u01b0u tr\u1eef tham chi\u1ebfu (pointer).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">S\u1eafp x\u1ebfp d\u1eef li\u1ec7u<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u trong b\u1ea3ng \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef v\u1eadt l\u00fd theo th\u1ee9 t\u1ef1 c\u1ee7a Clustered Index.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u kh\u00f4ng b\u1ecb thay \u0111\u1ed5i th\u1ee9 t\u1ef1 l\u01b0u tr\u1eef v\u1eadt l\u00fd, ch\u1ec9 m\u1ee5c l\u01b0u tham chi\u1ebfu \u0111\u1ebfn v\u1ecb tr\u00ed c\u1ee7a d\u1eef li\u1ec7u.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">S\u1ed1 l\u01b0\u1ee3ng ch\u1ec9 m\u1ee5c<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1ed9t b\u1ea3ng ch\u1ec9 c\u00f3 th\u1ec3 c\u00f3 m\u1ed9t Clustered Index, v\u00ec d\u1eef li\u1ec7u v\u1eadt l\u00fd ch\u1ec9 \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp theo m\u1ed9t th\u1ee9 t\u1ef1 duy nh\u1ea5t.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1ed9t b\u1ea3ng c\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u Non-Clustered Index.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng gian l\u01b0u tr\u1eef<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng y\u00eau c\u1ea7u th\u00eam kh\u00f4ng gian l\u01b0u tr\u1eef cho ch\u1ec9 m\u1ee5c (d\u1eef li\u1ec7u t\u1ef1 s\u1eafp x\u1ebfp).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Y\u00eau c\u1ea7u th\u00eam kh\u00f4ng gian l\u01b0u tr\u1eef \u0111\u1ec3 l\u01b0u tr\u1eef ch\u1ec9 m\u1ee5c v\u00e0 c\u00e1c tham chi\u1ebfu.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">T\u1ed1c \u0111\u1ed9 truy v\u1ea5n<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Nhanh h\u01a1n khi truy v\u1ea5n c\u00e1c d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp ho\u1eb7c l\u1ecdc theo c\u1ed9t \u0111\u01b0\u1ee3c l\u1eadp Clustered Index.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1eadm h\u01a1n v\u00ec c\u1ea7n tra c\u1ee9u tham chi\u1ebfu (pointer) \u0111\u1ec3 t\u00ecm v\u1ecb tr\u00ed d\u1eef li\u1ec7u th\u1ef1c trong b\u1ea3ng.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng ph\u1ed5 bi\u1ebfn<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u01b0\u1eddng \u0111\u01b0\u1ee3c t\u1ea1o tr\u00ean Primary Key \u0111\u1ec3 s\u1eafp x\u1ebfp v\u00e0 t\u0103ng t\u1ed1c \u0111\u1ed9 truy v\u1ea5n d\u1ef1a tr\u00ean c\u1ed9t ch\u00ednh.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u01b0\u1eddng \u0111\u01b0\u1ee3c t\u1ea1o tr\u00ean c\u00e1c c\u1ed9t th\u01b0\u1eddng xuy\u00ean d\u00f9ng trong t\u00ecm ki\u1ebfm ho\u1eb7c l\u1ecdc d\u1eef li\u1ec7u (<\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">JOIN<\/span><span style=\"font-weight: 400;\">).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Truy v\u1ea5n ph\u1ea1m vi (Range Query)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Hi\u1ec7u qu\u1ea3 cao khi th\u1ef1c hi\u1ec7n c\u00e1c truy v\u1ea5n ph\u1ea1m vi (<\/span><span style=\"font-weight: 400;\">BETWEEN<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&lt;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&gt;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">ORDER BY<\/span><span style=\"font-weight: 400;\">).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">K\u00e9m hi\u1ec7u qu\u1ea3 h\u01a1n trong c\u00e1c truy v\u1ea5n ph\u1ea1m vi v\u00ec c\u1ea7n tham chi\u1ebfu th\u00eam.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Thay \u0111\u1ed5i d\u1eef li\u1ec7u (<\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">UPDATE<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\">)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Thay \u0111\u1ed5i d\u1eef li\u1ec7u c\u00f3 th\u1ec3 ch\u1eadm h\u01a1n v\u00ec c\u1ea7n s\u1eafp x\u1ebfp l\u1ea1i d\u1eef li\u1ec7u trong b\u1ea3ng \u0111\u1ec3 duy tr\u00ec th\u1ee9 t\u1ef1 c\u1ee7a Clustered Index.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn th\u1ee9 t\u1ef1 l\u01b0u tr\u1eef, nh\u01b0ng c\u1ea7n c\u1eadp nh\u1eadt ch\u1ec9 m\u1ee5c t\u01b0\u01a1ng \u1ee9ng v\u1edbi thay \u0111\u1ed5i d\u1eef li\u1ec7u.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">V\u00ed d\u1ee5\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> c\u00f3 c\u1ed9t <\/span><span style=\"font-weight: 400;\">emp_id<\/span><span style=\"font-weight: 400;\"> l\u00e0 Primary Key, Clustered Index s\u1ebd s\u1eafp x\u1ebfp d\u1eef li\u1ec7u theo th\u1ee9 t\u1ef1 <\/span><span style=\"font-weight: 400;\">emp_id<\/span><span style=\"font-weight: 400;\">.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Non-Clustered Index c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c t\u1ea1o tr\u00ean c\u1ed9t <\/span><span style=\"font-weight: 400;\">email<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 t\u0103ng t\u1ed1c \u0111\u1ed9 truy v\u1ea5n c\u00e1c b\u1ea3n ghi d\u1ef1a tr\u00ean t\u00ean.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Tr\u00ecnh b\u00e0y m\u1ed9t s\u1ed1 ph\u01b0\u01a1ng ph\u00e1p b\u1ea3o m\u1eadt MySQL\u00a0<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">B\u1ea3o m\u1eadt MySQL l\u00e0 m\u1ed9t b\u01b0\u1edbc quan tr\u1ecdng \u0111\u1ec3 b\u1ea3o v\u1ec7 d\u1eef li\u1ec7u kh\u1ecfi c\u00e1c m\u1ed1i \u0111e d\u1ecda ti\u1ec1m \u1ea9n. M\u1ed9t s\u1ed1 ph\u01b0\u01a1ng ph\u00e1p b\u1ea3o m\u1eadt MySQL bao g\u1ed3m:<\/span><\/p>\n<ul>\n<li aria-level=\"1\"><b>Thi\u1ebft l\u1eadp m\u1eadt kh\u1ea9u m\u1ea1nh cho ng\u01b0\u1eddi d\u00f9ng:<\/b><\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng m\u1eadt kh\u1ea9u ph\u1ee9c t\u1ea1p ch\u1ee9a k\u00fd t\u1ef1 \u0111\u1eb7c bi\u1ec7t, ch\u1eef in hoa, in th\u01b0\u1eddng v\u00e0 s\u1ed1.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u1eb7t m\u1eadt kh\u1ea9u khi t\u1ea1o ng\u01b0\u1eddi d\u00f9ng v\u00e0 thay \u0111\u1ed5i m\u1eadt kh\u1ea9u \u0111\u1ecbnh k\u1ef3<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>S\u1eed d\u1ee5ng quy\u1ec1n t\u1ed1i thi\u1ec3u<\/b><span style=\"font-weight: 400;\">:<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ch\u1ec9 c\u1ea5p quy\u1ec1n c\u1ea7n thi\u1ebft cho ng\u01b0\u1eddi d\u00f9ng \u0111\u1ec3 h\u1ea1n ch\u1ebf c\u00e1c t\u00e1c v\u1ee5 kh\u00f4ng mong mu\u1ed1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Tr\u00e1nh s\u1eed d\u1ee5ng t\u00e0i kho\u1ea3n root cho c\u00e1c ho\u1ea1t \u0111\u1ed9ng th\u00f4ng th\u01b0\u1eddng.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ki\u1ec3m so\u00e1t quy\u1ec1n truy c\u1eadp b\u1eb1ng \u0111\u1ecba ch\u1ec9 (Host)<\/b><span style=\"font-weight: 400;\">: Gi\u1edbi h\u1ea1n quy\u1ec1n truy c\u1eadp c\u1ee7a ng\u01b0\u1eddi d\u00f9ng t\u1eeb c\u00e1c \u0111\u1ecba ch\u1ec9 c\u1ee5 th\u1ec3, v\u00ed d\u1ee5: localhost ho\u1eb7c m\u1ed9t IP x\u00e1c \u0111\u1ecbnh.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>S\u1eed d\u1ee5ng giao th\u1ee9c SSL<\/b><span style=\"font-weight: 400;\">: B\u1eadt SSL \u0111\u1ec3 m\u00e3 h\u00f3a k\u1ebft n\u1ed1i gi\u1eefa m\u00e1y kh\u00e1ch v\u00e0 m\u00e1y ch\u1ee7 MySQL, gi\u00fap ng\u0103n ch\u1eb7n vi\u1ec7c nghe l\u00e9n d\u1eef li\u1ec7u trong m\u1ea1ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>X\u00f3a ng\u01b0\u1eddi d\u00f9ng kh\u00f4ng c\u1ea7n thi\u1ebft<\/b><span style=\"font-weight: 400;\">: Lo\u1ea1i b\u1ecf c\u00e1c t\u00e0i kho\u1ea3n kh\u00f4ng s\u1eed d\u1ee5ng ho\u1eb7c kh\u00f4ng r\u00f5 ngu\u1ed3n g\u1ed1c<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>B\u1ea3o v\u1ec7 file c\u1ea5u h\u00ecnh<\/b><span style=\"font-weight: 400;\">: \u0110\u1ea3m b\u1ea3o file c\u1ea5u h\u00ecnh MySQL (my.cnf) ch\u1ec9 c\u00f3 quy\u1ec1n \u0111\u1ecdc v\u00e0 ghi cho t\u00e0i kho\u1ea3n qu\u1ea3n tr\u1ecb.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Gi\u00e1m s\u00e1t v\u00e0 ghi log<\/b><span style=\"font-weight: 400;\">: B\u1eadt log truy c\u1eadp v\u00e0 gi\u00e1m s\u00e1t c\u00e1c ho\u1ea1t \u0111\u1ed9ng \u0111\u00e1ng ng\u1edd trong MySQL \u0111\u1ec3 ph\u00e1t hi\u1ec7n s\u1edbm c\u00e1c m\u1ed1i nguy c\u01a1.<\/span><\/li>\n<\/ul>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 t\u1ea1o ng\u01b0\u1eddi d\u00f9ng m\u1edbi v\u00e0 c\u1ea5p quy\u1ec1n?<\/b><\/h3>\n<h4><b>T\u1ea1o ng\u01b0\u1eddi d\u00f9ng m\u1edbi<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">CREATE USER<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 t\u1ea1o ng\u01b0\u1eddi d\u00f9ng:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">username<\/span><span style=\"font-weight: 400;\">: T\u00ean ng\u01b0\u1eddi d\u00f9ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">hostname<\/span><span style=\"font-weight: 400;\">: M\u00e1y ch\u1ee7 m\u00e0 ng\u01b0\u1eddi d\u00f9ng \u0111\u01b0\u1ee3c ph\u00e9p k\u1ebft n\u1ed1i, v\u00ed d\u1ee5: <\/span><span style=\"font-weight: 400;\">localhost<\/span><span style=\"font-weight: 400;\"> (ch\u1ec9 t\u1eeb m\u00e1y c\u1ee5c b\u1ed9) ho\u1eb7c <\/span><span style=\"font-weight: 400;\">%<\/span><span style=\"font-weight: 400;\"> (cho ph\u00e9p t\u1eeb b\u1ea5t k\u1ef3 m\u00e1y ch\u1ee7 n\u00e0o &#8211; kh\u00f4ng khuy\u1ebfn ngh\u1ecb v\u00ec l\u00fd do b\u1ea3o m\u1eadt).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">password<\/span><span style=\"font-weight: 400;\">: M\u1eadt kh\u1ea9u ng\u01b0\u1eddi d\u00f9ng.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u1ea1o ng\u01b0\u1eddi d\u00f9ng <\/span><span style=\"font-weight: 400;\">john<\/span><span style=\"font-weight: 400;\"> v\u1edbi quy\u1ec1n truy c\u1eadp t\u1eeb m\u00e1y c\u1ee5c b\u1ed9, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE USER 'john'@'localhost' IDENTIFIED BY 'strong_password';<\/span><\/pre>\n<h4><b>C\u1ea5p quy\u1ec1n<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">L\u1ec7nh <\/span><span style=\"font-weight: 400;\">GRANT<\/span><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 c\u1ea5p quy\u1ec1n cho ng\u01b0\u1eddi d\u00f9ng tr\u00ean c\u00e1c c\u1ea5p \u0111\u1ed9 kh\u00e1c nhau nh\u01b0 to\u00e0n c\u01a1 s\u1edf d\u1eef li\u1ec7u, b\u1ea3ng ho\u1eb7c c\u1ed9t.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">GRANT privileges ON database_name.table_name TO 'username'@'hostname';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">privileges<\/span><span style=\"font-weight: 400;\">: C\u00e1c quy\u1ec1n c\u1ea7n c\u1ea5p nh\u01b0 <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">UPDATE<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\">, ho\u1eb7c <\/span><span style=\"font-weight: 400;\">ALL PRIVILEGES<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 c\u1ea5p to\u00e0n b\u1ed9 quy\u1ec1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">database_name.table_name<\/span><span style=\"font-weight: 400;\">: C\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 b\u1ea3ng m\u00e0 quy\u1ec1n \u00e1p d\u1ee5ng (<\/span><span style=\"font-weight: 400;\">*.*<\/span><span style=\"font-weight: 400;\"> cho to\u00e0n b\u1ed9 c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 b\u1ea3ng).<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 <\/span><b>c<\/b><span style=\"font-weight: 400;\">\u1ea5p quy\u1ec1n <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\"> tr\u00ean b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> trong c\u01a1 s\u1edf d\u1eef li\u1ec7u <\/span><i><span style=\"font-weight: 400;\">company<\/span><\/i><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">GRANT SELECT, INSERT ON company.employees TO 'john'@'localhost';<\/span><\/pre>\n<h4><b>Thu h\u1ed3i quy\u1ec1n (REVOKE)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">REVOKE privileges ON database_name.table_name FROM 'username'@'hostname';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 thu h\u1ed3i quy\u1ec1n <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\"> tr\u00ean b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> t\u1eeb ng\u01b0\u1eddi d\u00f9ng <\/span><i><span style=\"font-weight: 400;\">john<\/span><\/i><span style=\"font-weight: 400;\">, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">REVOKE INSERT ON company.employees FROM 'john'@'localhost';<\/span><\/pre>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 thi\u1ebft l\u1eadp c\u00e1c ph\u01b0\u01a1ng th\u1ee9c backup d\u1eef li\u1ec7u?\u00a0<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Backup d\u1eef li\u1ec7u trong MySQL l\u00e0 m\u1ed9t ph\u1ea7n quan tr\u1ecdng \u0111\u1ec3 b\u1ea3o v\u1ec7 d\u1eef li\u1ec7u kh\u1ecfi m\u1ea5t m\u00e1t do l\u1ed7i h\u1ec7 th\u1ed1ng, ph\u1ea7n c\u1ee9ng ho\u1eb7c c\u00e1c s\u1ef1 c\u1ed1 b\u1ea5t ng\u1edd kh\u00e1c. MySQL h\u1ed7 tr\u1ee3 nhi\u1ec1u ph\u01b0\u01a1ng th\u1ee9c backup, bao g\u1ed3m Full Backup (sao l\u01b0u to\u00e0n b\u1ed9) v\u00e0 Incremental Backup (sao l\u01b0u gia t\u0103ng).\u00a0<\/span><\/p>\n<h4><b>Full Backup<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Full Backup l\u00e0 qu\u00e1 tr\u00ecnh sao l\u01b0u to\u00e0n b\u1ed9 d\u1eef li\u1ec7u c\u1ee7a c\u01a1 s\u1edf d\u1eef li\u1ec7u, bao g\u1ed3m c\u1ea3 c\u1ea5u tr\u00fac v\u00e0 d\u1eef li\u1ec7u trong c\u00e1c b\u1ea3ng. Lo\u1ea1i backup n\u00e0y th\u01b0\u1eddng \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n \u0111\u1ecbnh k\u1ef3 nh\u01b0 h\u00e0ng ng\u00e0y ho\u1eb7c h\u00e0ng tu\u1ea7n.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1ch th\u1ef1c hi\u1ec7n Full Backup:<\/span><\/p>\n<p><b>B\u01b0\u1edbc 1: S\u1eed d\u1ee5ng c\u00f4ng c\u1ee5 mysqldump<\/b><span style=\"font-weight: 400;\"> v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">mysqldump -u [username] -p [database_name] &gt; [backup_file.sql]<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">[username]<\/span><span style=\"font-weight: 400;\">: T\u00ean ng\u01b0\u1eddi d\u00f9ng MySQL.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">[database_name]<\/span><span style=\"font-weight: 400;\">: T\u00ean c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u1ea7n sao l\u01b0u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">[backup_file.sql]<\/span><span style=\"font-weight: 400;\">: T\u00ean t\u1ec7p \u0111\u1ec3 l\u01b0u b\u1ea3n sao l\u01b0u.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 sao l\u01b0u c\u01a1 s\u1edf d\u1eef li\u1ec7u <\/span><i><span style=\"font-weight: 400;\">company<\/span><\/i><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">mysqldump -u root -p company &gt; company_backup.sql<\/span><\/pre>\n<p><b>B\u01b0\u1edbc 2: Sao l\u01b0u t\u1ea5t c\u1ea3 c\u01a1 s\u1edf d\u1eef li\u1ec7u:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">D\u00f9ng t\u00f9y ch\u1ecdn <\/span><span style=\"font-weight: 400;\">&#8211;all-databases<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 sao l\u01b0u to\u00e0n b\u1ed9 c\u01a1 s\u1edf d\u1eef li\u1ec7u tr\u00ean m\u00e1y ch\u1ee7 MySQL:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">mysqldump -u root -p --all-databases &gt; full_backup.sql<\/span><\/pre>\n<p><b>B\u01b0\u1edbc 3: N\u00e9n file backup:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ec3 ti\u1ebft ki\u1ec7m dung l\u01b0\u1ee3ng, ta c\u00f3 th\u1ec3 n\u00e9n file v\u1edbi c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">mysqldump -u root -p company | gzip &gt; company_backup.sql.gz<\/span><\/pre>\n<h4><b>Incremental Backup (Sao l\u01b0u gia t\u0103ng)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Incremental Backup ch\u1ec9 sao l\u01b0u nh\u1eefng thay \u0111\u1ed5i \u0111\u00e3 di\u1ec5n ra k\u1ec3 t\u1eeb l\u1ea7n backup tr\u01b0\u1edbc \u0111\u00f3. Lo\u1ea1i backup n\u00e0y ti\u1ebft ki\u1ec7m th\u1eddi gian v\u00e0 dung l\u01b0\u1ee3ng l\u01b0u tr\u1eef h\u01a1n so v\u1edbi Full Backup.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1ch th\u1ef1c hi\u1ec7n:<\/span><\/p>\n<p><b>B\u01b0\u1edbc 1: B\u1eadt ch\u1ebf \u0111\u1ed9 Binary Log<\/b><\/p>\n<p><span style=\"font-weight: 400;\">MySQL s\u1eed d\u1ee5ng Binary Log \u0111\u1ec3 ghi l\u1ea1i c\u00e1c thay \u0111\u1ed5i trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. \u0110\u00e2y l\u00e0 \u0111i\u1ec1u ki\u1ec7n ti\u00ean quy\u1ebft \u0111\u1ec3 th\u1ef1c hi\u1ec7n Incremental Backup. B\u1eadt ch\u1ebf \u0111\u1ed9 Binary Log trong file c\u1ea5u h\u00ecnh MySQL (<\/span><span style=\"font-weight: 400;\">my.cnf<\/span><span style=\"font-weight: 400;\">) v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">[mysqld]\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">log-bin=mysql-bin\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">server-id=1<\/span><\/pre>\n<p><strong>B\u01b0\u1edbc 2: Kh\u1edfi \u0111\u1ed9ng l\u1ea1i MySQL<\/strong><\/p>\n<p><b>B\u01b0\u1edbc 3: Sao l\u01b0u Binary Log<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Sao ch\u00e9p c\u00e1c file Binary Log \u0111\u1ec3 th\u1ef1c hi\u1ec7n Incremental Backup v\u1edbi c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">mysqlbinlog [binary_log_file] &gt; incremental_backup.sql<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">[binary_log_file]<\/span><span style=\"font-weight: 400;\"> l\u00e0 t\u00ean file log<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\"><strong>B\u01b0\u1edbc 4: Sau khi sao l\u01b0u Binary Log<\/strong>, b\u1ea1n c\u00f3 th\u1ec3 x\u00f3a log c\u0169 \u0111\u1ec3 ti\u1ebft ki\u1ec7m dung l\u01b0\u1ee3ng v\u1edbi c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">RESET MASTER;<\/span><\/pre>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 t\u1ed1i \u01b0u h\u00f3a c\u1ea5u tr\u00fac b\u1ea3ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">T\u1ed1i \u01b0u h\u00f3a c\u1ea5u tr\u00fac b\u1ea3ng v\u00e0 ch\u1ec9 m\u1ee5c l\u00e0 m\u1ed9t b\u01b0\u1edbc quan tr\u1ecdng \u0111\u1ec3 c\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t c\u01a1 s\u1edf d\u1eef li\u1ec7u MySQL. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 c\u00e1c ph\u01b0\u01a1ng ph\u00e1p:<\/span><\/p>\n<h4><b>Ch\u1ecdn ki\u1ec3u d\u1eef li\u1ec7u ph\u00f9 h\u1ee3p<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng ki\u1ec3u d\u1eef li\u1ec7u ch\u00ednh x\u00e1c v\u00e0 ph\u00f9 h\u1ee3p v\u1edbi ph\u1ea1m vi gi\u00e1 tr\u1ecb l\u01b0u tr\u1eef \u0111\u1ec3 ti\u1ebft ki\u1ec7m kh\u00f4ng gian l\u01b0u tr\u1eef v\u00e0 t\u0103ng t\u1ed1c \u0111\u1ed9 x\u1eed l\u00fd.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">INT<\/span><span style=\"font-weight: 400;\"> thay v\u00ec <\/span><span style=\"font-weight: 400;\">BIGINT<\/span><span style=\"font-weight: 400;\"> n\u1ebfu gi\u00e1 tr\u1ecb kh\u00f4ng v\u01b0\u1ee3t qu\u00e1 ph\u1ea1m vi c\u1ee7a <\/span><span style=\"font-weight: 400;\">INT<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">VARCHAR<\/span><span style=\"font-weight: 400;\"> thay v\u00ec <\/span><span style=\"font-weight: 400;\">TEXT<\/span><span style=\"font-weight: 400;\"> cho c\u00e1c chu\u1ed7i ng\u1eafn.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ch\u1ecdn ki\u1ec3u d\u1eef li\u1ec7u ng\u00e0y nh\u01b0 <\/span><span style=\"font-weight: 400;\">DATE<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">DATETIME<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">TIMESTAMP<\/span><span style=\"font-weight: 400;\"> ph\u00f9 h\u1ee3p v\u1edbi y\u00eau c\u1ea7u.<\/span><\/li>\n<\/ul>\n<h4><b>Tr\u00e1nh s\u1eed d\u1ee5ng ki\u1ec3u d\u1eef li\u1ec7u kh\u00f4ng c\u1ea7n thi\u1ebft<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Tr\u00e1nh s\u1eed d\u1ee5ng c\u00e1c ki\u1ec3u d\u1eef li\u1ec7u qu\u00e1 l\u1edbn cho c\u00e1c c\u1ed9t \u00edt \u0111\u01b0\u1ee3c truy c\u1eadp. V\u00ed d\u1ee5 d\u00f9ng ENUM ho\u1eb7c SET thay cho VARCHAR khi c\u1ed9t ch\u1ec9 ch\u1ee9a m\u1ed9t s\u1ed1 gi\u00e1 tr\u1ecb c\u1ed1 \u0111\u1ecbnh.<\/span><\/p>\n<h4><b>Chu\u1ea9n h\u00f3a c\u01a1 s\u1edf d\u1eef li\u1ec7u<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">\u00c1p d\u1ee5ng c\u00e1c quy t\u1eafc chu\u1ea9n h\u00f3a \u0111\u1ec3 lo\u1ea1i b\u1ecf s\u1ef1 d\u01b0 th\u1eeba d\u1eef li\u1ec7u. Tuy nhi\u00ean, \u0111\u1ed1i v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng l\u1edbn, c\u00e2n nh\u1eafc gi\u1eefa chu\u1ea9n h\u00f3a v\u00e0 hi\u1ec7u su\u1ea5t (denormalization) \u0111\u1ec3 gi\u1ea3m s\u1ed1 l\u01b0\u1ee3ng JOIN.<\/span><\/p>\n<h4><b>S\u1eed d\u1ee5ng Partitioning<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Chia b\u1ea3ng l\u1edbn th\u00e0nh c\u00e1c ph\u1ea7n nh\u1ecf h\u01a1n b\u1eb1ng Partitioning \u0111\u1ec3 c\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t truy v\u1ea5n, \u0111\u1eb7c bi\u1ec7t v\u1edbi c\u00e1c b\u1ea3ng c\u00f3 h\u00e0ng tri\u1ec7u b\u1ea3n ghi.<\/span><\/p>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 t\u1ed1i \u01b0u h\u00f3a c\u1ea5u tr\u00fac c\u00e1c ch\u1ec9 m\u1ee5c?<\/b><\/h3>\n<h4><b>T\u1ea1o ch\u1ec9 m\u1ee5c cho c\u00e1c c\u1ed9t th\u01b0\u1eddng xuy\u00ean \u0111\u01b0\u1ee3c truy v\u1ea5n<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">\u0110\u1ea3m b\u1ea3o c\u00e1c c\u1ed9t trong m\u1ec7nh \u0111\u1ec1 <\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">JOIN<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">ORDER BY<\/span><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c ch\u1ec9 m\u1ee5c \u0111\u1ec3 t\u0103ng t\u1ed1c \u0111\u1ed9 truy v\u1ea5n.<\/span><\/p>\n<h4><b>S\u1eed d\u1ee5ng ch\u1ec9 m\u1ee5c ph\u00f9 h\u1ee3p v\u1edbi lo\u1ea1i truy v\u1ea5n<\/b><\/h4>\n<ul>\n<li><b>B-Tree Index:<\/b><span style=\"font-weight: 400;\"> Ph\u00f9 h\u1ee3p v\u1edbi h\u1ea7u h\u1ebft c\u00e1c truy v\u1ea5n th\u00f4ng th\u01b0\u1eddng (<\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&gt;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&lt;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">BETWEEN<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">LIKE &#8216;abc%&#8217;<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li><b>Hash Index:<\/b><span style=\"font-weight: 400;\"> Nhanh h\u01a1n cho c\u00e1c truy v\u1ea5n ch\u00ednh x\u00e1c (<\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">), nh\u01b0ng kh\u00f4ng h\u1ed7 tr\u1ee3 ph\u1ea1m vi.<\/span><\/li>\n<li><b>Full-Text Index:<\/b><span style=\"font-weight: 400;\"> H\u1eefu \u00edch cho t\u00ecm ki\u1ebfm v\u0103n b\u1ea3n v\u1edbi c\u00e1c c\u1ed9t ki\u1ec3u <\/span><span style=\"font-weight: 400;\">TEXT<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">VARCHAR<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n<h4><b>Ch\u1ec9 s\u1ed1 nhi\u1ec1u c\u1ed9t (Composite Index)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">N\u1ebfu truy v\u1ea5n s\u1eed d\u1ee5ng nhi\u1ec1u c\u1ed9t c\u00f9ng l\u00fac, h\u00e3y t\u1ea1o ch\u1ec9 m\u1ee5c tr\u00ean c\u00e1c c\u1ed9t \u0111\u00f3 v\u00e0 \u0111\u1ea3m b\u1ea3o th\u1ee9 t\u1ef1 c\u00e1c c\u1ed9t trong ch\u1ec9 m\u1ee5c ph\u00f9 h\u1ee3p v\u1edbi th\u1ee9 t\u1ef1 trong truy v\u1ea5n.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: N\u1ebfu th\u01b0\u1eddng t\u00ecm ki\u1ebfm theo <\/span><i><span style=\"font-weight: 400;\">name<\/span><\/i><span style=\"font-weight: 400;\"> v\u00e0 <\/span><i><span style=\"font-weight: 400;\">age<\/span><\/i><span style=\"font-weight: 400;\">, h\u00e3y t\u1ea1o ch\u1ec9 m\u1ee5c (<\/span><i><span style=\"font-weight: 400;\">name,<\/span><\/i> <i><span style=\"font-weight: 400;\">age<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><\/p>\n<h4><b>Kh\u00f4ng t\u1ea1o qu\u00e1 nhi\u1ec1u ch\u1ec9 m\u1ee5c<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Qu\u00e1 nhi\u1ec1u ch\u1ec9 m\u1ee5c l\u00e0m ch\u1eadm thao t\u00e1c ghi (<\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">UPDATE<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\">). H\u00e3y ki\u1ec3m tra ch\u1ec9 m\u1ee5c n\u00e0o th\u1ef1c s\u1ef1 c\u1ea7n.<\/span><\/p>\n<h4><b>S\u1eed d\u1ee5ng ch\u1ec9 m\u1ee5c duy nh\u1ea5t (Unique Index)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng ch\u1ec9 m\u1ee5c duy nh\u1ea5t \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n d\u1eef li\u1ec7u, \u0111\u1eb7c bi\u1ec7t v\u1edbi c\u00e1c c\u1ed9t nh\u01b0 <\/span><i><span style=\"font-weight: 400;\">email<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">username<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><b>Ki\u1ec3m tra v\u00e0 b\u1ea3o tr\u00ec ch\u1ec9 m\u1ee5c<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">ANALYZE TABLE<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">OPTIMIZE<\/span> <span style=\"font-weight: 400;\">TABLE<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 \u0111\u00e1nh gi\u00e1 v\u00e0 t\u1ed1i \u01b0u h\u00f3a hi\u1ec7u su\u1ea5t c\u1ee7a c\u00e1c ch\u1ec9 m\u1ee5c.<\/span><\/p>\n<h3><b>Sharding l\u00e0 g\u00ec? Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng sharding?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Sharding l\u00e0 m\u1ed9t k\u1ef9 thu\u1eadt ph\u00e2n chia d\u1eef li\u1ec7u trong c\u01a1 s\u1edf d\u1eef li\u1ec7u th\u00e0nh c\u00e1c ph\u00e2n \u0111o\u1ea1n nh\u1ecf h\u01a1n (g\u1ecdi l\u00e0 shard) v\u00e0 ph\u00e2n ph\u1ed1i c\u00e1c ph\u00e2n \u0111o\u1ea1n n\u00e0y tr\u00ean nhi\u1ec1u m\u00e1y ch\u1ee7 kh\u00e1c nhau. M\u1ed7i shard ho\u1ea1t \u0111\u1ed9ng nh\u01b0 m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u1ed9c l\u1eadp, ch\u1ee9a m\u1ed9t ph\u1ea7n d\u1eef li\u1ec7u t\u1ed5ng th\u1ec3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Thay v\u00ec l\u01b0u tr\u1eef to\u00e0n b\u1ed9 d\u1eef li\u1ec7u tr\u00ean m\u1ed9t m\u00e1y ch\u1ee7 duy nh\u1ea5t, Sharding gi\u00fap ph\u00e2n ph\u1ed1i d\u1eef li\u1ec7u \u0111\u1ec3 gi\u1ea3m t\u1ea3i v\u00e0 c\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t.<\/span><\/p>\n<h4><b>C\u00e1ch ho\u1ea1t \u0111\u1ed9ng c\u1ee7a Sharding<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">D\u1eef li\u1ec7u \u0111\u01b0\u1ee3c chia th\u00e0nh c\u00e1c shard d\u1ef1a tr\u00ean m\u1ed9t sharding key, th\u01b0\u1eddng l\u00e0 m\u1ed9t c\u1ed9t ho\u1eb7c m\u1ed9t nh\u00f3m c\u1ed9t trong b\u1ea3ng. Sharding key ph\u1ea3i \u0111\u1ea3m b\u1ea3o t\u00ednh duy nh\u1ea5t v\u00e0 ph\u00e2n ph\u1ed1i d\u1eef li\u1ec7u \u0111\u1ec1u \u0111\u1ec3 tr\u00e1nh t\u00ecnh tr\u1ea1ng shard qu\u00e1 t\u1ea3i ho\u1eb7c m\u1ea5t c\u00e2n b\u1eb1ng t\u1ea3i. M\u1ed9t s\u1ed1 ph\u01b0\u01a1ng ph\u00e1p Sharding ph\u1ed5 bi\u1ebfn bao g\u1ed3m:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Horizontal Sharding (Ph\u00e2n \u0111o\u1ea1n ngang):<\/b><span style=\"font-weight: 400;\"> D\u1eef li\u1ec7u \u0111\u01b0\u1ee3c chia theo h\u00e0ng. V\u00ed d\u1ee5: m\u1ed7i shard ch\u1ee9a m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c b\u1ea3n ghi d\u1ef1a tr\u00ean <\/span><span style=\"font-weight: 400;\">UserID<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">Region<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Vertical Sharding (Ph\u00e2n \u0111o\u1ea1n d\u1ecdc):<\/b><span style=\"font-weight: 400;\"> D\u1eef li\u1ec7u \u0111\u01b0\u1ee3c chia theo c\u1ed9t. V\u00ed d\u1ee5: c\u00e1c c\u1ed9t quan tr\u1ecdng (th\u01b0\u1eddng xuy\u00ean truy c\u1eadp) \u0111\u01b0\u1ee3c \u0111\u1eb7t tr\u00ean m\u1ed9t shard ri\u00eang.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Hash Sharding:<\/b><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng h\u00e0m b\u0103m tr\u00ean gi\u00e1 tr\u1ecb c\u1ee7a sharding key \u0111\u1ec3 ph\u00e2n ph\u1ed1i d\u1eef li\u1ec7u v\u00e0o c\u00e1c shard.<\/span><\/li>\n<\/ul>\n<h4><b>\u01afu v\u00e0 nh\u01b0\u1ee3c \u0111i\u1ec3m c\u1ee7a Sharding<\/b><\/h4>\n<table>\n<tbody>\n<tr>\n<td><b>\u01afu \u0111i\u1ec3m<\/b><\/td>\n<td><b>Nh\u01b0\u1ee3c \u0111i\u1ec3m<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>T\u0103ng hi\u1ec7u su\u1ea5t:<\/b><span style=\"font-weight: 400;\"> X\u1eed l\u00fd t\u1ea3i \u0111\u1ecdc\/ghi l\u1edbn d\u1ec5 d\u00e0ng.<\/span><\/td>\n<td><b>Ph\u1ee9c t\u1ea1p h\u01a1n:<\/b><span style=\"font-weight: 400;\"> Qu\u1ea3n l\u00fd nhi\u1ec1u m\u00e1y ch\u1ee7 shard ph\u1ee9c t\u1ea1p h\u01a1n m\u1ed9t m\u00e1y ch\u1ee7 duy nh\u1ea5t.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>M\u1edf r\u1ed9ng d\u1ec5 d\u00e0ng:<\/b><span style=\"font-weight: 400;\"> Th\u00eam shard \u0111\u1ec3 m\u1edf r\u1ed9ng h\u1ec7 th\u1ed1ng.<\/span><\/td>\n<td><b>Kh\u00f3 kh\u0103n trong truy v\u1ea5n li\u00ean shard:<\/b><span style=\"font-weight: 400;\"> JOIN ho\u1eb7c t\u1ed5ng h\u1ee3p d\u1eef li\u1ec7u tr\u00ean nhi\u1ec1u shard m\u1ea5t th\u1eddi gian h\u01a1n.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Gi\u1ea3m r\u1ee7i ro s\u1ef1 c\u1ed1:<\/b><span style=\"font-weight: 400;\"> S\u1ef1 c\u1ed1 tr\u00ean m\u1ed9t shard kh\u00f4ng \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn to\u00e0n h\u1ec7 th\u1ed1ng.<\/span><\/td>\n<td><b>C\u00e2n b\u1eb1ng t\u1ea3i:<\/b><span style=\"font-weight: 400;\"> Ph\u00e2n ph\u1ed1i d\u1eef li\u1ec7u kh\u00f4ng \u0111\u1ec1u c\u00f3 th\u1ec3 d\u1eabn \u0111\u1ebfn shard qu\u00e1 t\u1ea3i.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Linh ho\u1ea1t v\u1edbi d\u1eef li\u1ec7u l\u1edbn:<\/b><span style=\"font-weight: 400;\"> Qu\u1ea3n l\u00fd c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u00f3 dung l\u01b0\u1ee3ng v\u01b0\u1ee3t qu\u00e1 gi\u1edbi h\u1ea1n ph\u1ea7n c\u1ee9ng.<\/span><\/td>\n<td><b>T\u0103ng \u0111\u1ed9 ph\u1ee9c t\u1ea1p:<\/b><span style=\"font-weight: 400;\"> Backup, \u0111\u1ed3ng b\u1ed9, v\u00e0 t\u00e1i ph\u00e2n ph\u1ed1i d\u1eef li\u1ec7u gi\u1eefa c\u00e1c shard kh\u00f3 kh\u0103n h\u01a1n.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng Sharding?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Sharding ph\u00f9 h\u1ee3p v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng l\u1edbn, ph\u1ee9c t\u1ea1p v\u00e0 c\u00f3 kh\u1ed1i l\u01b0\u1ee3ng d\u1eef li\u1ec7u l\u1edbn. Sharding n\u00ean \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng khi:<\/span><\/p>\n<ul>\n<li><b>D\u1eef li\u1ec7u qu\u00e1 l\u1edbn \u0111\u1ec3 l\u01b0u tr\u1eef tr\u00ean m\u1ed9t m\u00e1y ch\u1ee7 duy nh\u1ea5t: <\/b><span style=\"font-weight: 400;\">Khi k\u00edch th\u01b0\u1edbc c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u01b0\u1ee3t qu\u00e1 dung l\u01b0\u1ee3ng \u1ed5 \u0111\u0129a ho\u1eb7c b\u1ed9 nh\u1edb c\u1ee7a m\u00e1y ch\u1ee7, Sharding cho ph\u00e9p chia nh\u1ecf d\u1eef li\u1ec7u \u0111\u1ec3 l\u01b0u tr\u1eef tr\u00ean nhi\u1ec1u m\u00e1y ch\u1ee7.<\/span><\/li>\n<li><b>Hi\u1ec7u su\u1ea5t truy v\u1ea5n gi\u1ea3m do t\u1ea3i n\u1eb7ng: <\/b><span style=\"font-weight: 400;\">Khi m\u1ed9t m\u00e1y ch\u1ee7 duy nh\u1ea5t kh\u00f4ng th\u1ec3 x\u1eed l\u00fd s\u1ed1 l\u01b0\u1ee3ng l\u1edbn truy v\u1ea5n \u0111\u1ecdc v\u00e0 ghi, Sharding ph\u00e2n t\u00e1n t\u1ea3i tr\u00ean nhi\u1ec1u m\u00e1y ch\u1ee7 \u0111\u1ec3 t\u0103ng hi\u1ec7u su\u1ea5t.<\/span><\/li>\n<li><b>C\u1ea7n m\u1edf r\u1ed9ng h\u1ec7 th\u1ed1ng theo chi\u1ec1u ngang (Horizontal Scaling): <\/b><span style=\"font-weight: 400;\">N\u1ebfu mu\u1ed1n t\u0103ng kh\u1ea3 n\u0103ng x\u1eed l\u00fd m\u00e0 kh\u00f4ng c\u1ea7n n\u00e2ng c\u1ea5p ph\u1ea7n c\u1ee9ng c\u1ee7a m\u00e1y ch\u1ee7 (vertical scaling), Sharding gi\u00fap m\u1edf r\u1ed9ng b\u1eb1ng c\u00e1ch th\u00eam nhi\u1ec1u m\u00e1y ch\u1ee7 h\u01a1n.<\/span><\/li>\n<li><b>D\u1eef li\u1ec7u c\u00f3 th\u1ec3 ph\u00e2n \u0111o\u1ea1n r\u00f5 r\u00e0ng: <\/b><span style=\"font-weight: 400;\">N\u1ebfu d\u1eef li\u1ec7u c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c chia nh\u1ecf d\u1ef1a tr\u00ean c\u00e1c sharding key t\u1ef1 nhi\u00ean, nh\u01b0 <\/span><span style=\"font-weight: 400;\">UserID<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">Region<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">Timestamp<\/span><span style=\"font-weight: 400;\">, th\u00ec Sharding l\u00e0 l\u1ef1a ch\u1ecdn ph\u00f9 h\u1ee3p.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_cau_hoi_phong_van_MySQL\"><\/span><b>T\u1ed5ng k\u1ebft c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">B\u00ean c\u1ea1nh n\u1eafm v\u1eefng c\u00e1c l\u00fd thuy\u1ebft t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn chuy\u00ean s\u00e2u, \u1ee9ng vi\u00ean c\u0169ng c\u1ea7n trang b\u1ecb th\u00eam m\u1ed9t s\u1ed1 c\u00e2u tr\u1ea3 l\u1eddi v\u1ec1 c\u00e1c kinh nghi\u1ec7m s\u1eed d\u1ee5ng th\u1ef1c ti\u1ec5n \u0111\u1ec3 c\u00f3 th\u1ec3 chinh ph\u1ee5c \u0111\u01b0\u1ee3c c\u00e1c nh\u00e0 tuy\u1ec3n d\u1ee5ng. <\/span><span style=\"font-weight: 400;\">ITviec hy v\u1ecdng b\u00e0i vi\u1ebft v\u1ec1 c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL tr\u00ean \u0111\u00e3 gi\u00fap \u00edch cho c\u00e1c b\u1ea1n trong qu\u00e1 tr\u00ecnh chu\u1ea9n b\u1ecb h\u00e0nh trang \u0111\u1ec3 c\u00f3 th\u1ec3 t\u00ecm \u0111\u01b0\u1ee3c v\u1ecb tr\u00ed ngh\u1ec1 nghi\u1ec7p ph\u00f9 h\u1ee3p.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL l\u00e0 m\u1ed9t trong nh\u1eefng h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u ph\u1ed5 bi\u1ebfn nh\u1ea5t, \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng r\u1ed9ng r\u00e3i trong c\u00e1c \u1ee9ng d\u1ee5ng t\u1eeb nh\u1ecf \u0111\u1ebfn l\u1edbn, n\u00ean s\u1ebd th\u01b0\u1eddng xu\u1ea5t hi\u1ec7n trong c\u00e1c bu\u1ed5i ph\u1ecfng v\u1ea5n li\u00ean quan \u0111\u1ebfn c\u01a1 s\u1edf d\u1eef li\u1ec7u. Danh s\u00e1ch 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL sau \u0111\u00e2y [&hellip;]<\/p>\n","protected":false},"author":209,"featured_media":84148,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109,105],"tags":[],"class_list":["post-84085","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it","category-phong-van-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn - ITviec Blog<\/title>\n<meta name=\"description\" content=\"Kh\u00e1m ph\u00e1 danh s\u00e1ch c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn, t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao, k\u00e8m c\u00e2u tr\u1ea3 l\u1eddi c\u1ef1c k\u1ef3 chi ti\u1ebft.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn\" \/>\n<meta property=\"og:description\" content=\"MySQL l\u00e0 m\u1ed9t trong nh\u1eefng h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u ph\u1ed5 bi\u1ebfn nh\u1ea5t, \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng r\u1ed9ng r\u00e3i trong c\u00e1c \u1ee9ng d\u1ee5ng t\u1eeb nh\u1ecf \u0111\u1ebfn l\u1edbn, n\u00ean s\u1ebd th\u01b0\u1eddng xu\u1ea5t hi\u1ec7n trong\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-16T08:54:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/01\/cau-hoi-phong-van-mysql-vippro.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"950\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"M\u1ef9 Duy\u00ean\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"M\u1ef9 Duy\u00ean\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"67 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn - ITviec Blog","description":"Kh\u00e1m ph\u00e1 danh s\u00e1ch c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn, t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao, k\u00e8m c\u00e2u tr\u1ea3 l\u1eddi c\u1ef1c k\u1ef3 chi ti\u1ebft.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/","og_locale":"vi_VN","og_type":"article","og_title":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn","og_description":"MySQL l\u00e0 m\u1ed9t trong nh\u1eefng h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u ph\u1ed5 bi\u1ebfn nh\u1ea5t, \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng r\u1ed9ng r\u00e3i trong c\u00e1c \u1ee9ng d\u1ee5ng t\u1eeb nh\u1ecf \u0111\u1ebfn l\u1edbn, n\u00ean s\u1ebd th\u01b0\u1eddng xu\u1ea5t hi\u1ec7n trong","og_url":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-01-16T08:54:34+00:00","og_image":[{"width":950,"height":500,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/01\/cau-hoi-phong-van-mysql-vippro.jpg","type":"image\/jpeg"}],"author":"M\u1ef9 Duy\u00ean","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"M\u1ef9 Duy\u00ean","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"67 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/"},"author":{"name":"M\u1ef9 Duy\u00ean","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7"},"headline":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn","datePublished":"2025-01-16T08:54:34+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/"},"wordCount":18014,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/01\/cau-hoi-phong-van-mysql-vippro.jpg","articleSection":["Chuy\u00ean m\u00f4n IT","Ph\u1ecfng v\u1ea5n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/","url":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/","name":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/01\/cau-hoi-phong-van-mysql-vippro.jpg","datePublished":"2025-01-16T08:54:34+00:00","description":"Kh\u00e1m ph\u00e1 danh s\u00e1ch c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn, t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao, k\u00e8m c\u00e2u tr\u1ea3 l\u1eddi c\u1ef1c k\u1ef3 chi ti\u1ebft.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/01\/cau-hoi-phong-van-mysql-vippro.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/01\/cau-hoi-phong-van-mysql-vippro.jpg","width":950,"height":500,"caption":"c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n mysql - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"Top 30+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n MySQL ph\u1ed5 bi\u1ebfn"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7","name":"M\u1ef9 Duy\u00ean","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","caption":"M\u1ef9 Duy\u00ean"},"url":"https:\/\/itviec.com\/blog\/author\/my-duyen\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/84085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/209"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=84085"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/84085\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/84148"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=84085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=84085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=84085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}