ÃËÀÂÀ 14 Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL M ySQL ɨɬɧɨɫɢɬɫɹ ɤ ɱɢɫɥɭ ɛɚɡ ɞɚɧɧɵɯ, ɨɛɟɫɩɟɱɢɜɚɸɳɢɯ ɧɚɢɛɨɥɟɟ ɩɪɨɫɬɨɟ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɟ ɧɚ ɜɫɟɯ ɩɥɚɬɮɨɪɦɚɯ. Ʉɪɨɦɟ ɬɨɝɨ, ɷɬɚ ɛɚɡɚ ɞɚɧɧɵɯ ɧɟ ɬɪɟɛɨɜɚɬɟɥɶɧɚ ɤ ɪɟɫɭɪɫɚɦ, ɩɨɷɬɨɦɭ ɦɨɠɟɬ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶɫɹ ɞɚɠɟ ɧɚ ɩɟɪɫɨɧɚɥɶɧɵɯ ɤɨɦɩɶɸɬɟɪɚɯ ɫ ɧɟɛɨɥɶɲɢɦ ɨɛɴɟɦɨɦ ɨɩɟɪɚɬɢɜɧɨɣ ɩɚɦɹɬɢ ɢ ɠɟɫɬɤɨɝɨ ɞɢɫɤɚ. ȼ ɫɜɹɡɢ ɫ ɷɬɢɦ ɪɚɡɪɚɛɨɬɱɢɤɢ, ɢɫɩɨɥɶɡɭɸɳɢɟ ɫɪɟɞɫɬɜɚ PHP, ɭɠɟ ɜ ɬɟɱɟɧɢɟ ɩɪɨɞɨɥɠɢɬɟɥɶɧɨɝɨ ɜɪɟɦɟɧɢ ɩɪɢɦɟɧɹɸɬ MySQL ɞɥɹ ɫɨɡɞɚɧɢɹ ɩɨɥɧɨɣ ɥɨɤɚɥɶɧɨɣ ɫɪɟɞɵ ɪɚɡɪɚɛɨɬɤɢ ɞɥɹ Web ɧɚ ɤɥɢɟɧɬɫɤɢɯ ɤɨɦɩɶɸɬɟɪɚɯ ɜɫɟɜɨɡɦɨɠɧɵɯ ɬɢɩɨɜ, ɞɚɠɟ ɧɚ ɩɨɪɬɚɬɢɜɧɵɯ ɤɨɦɩɶɸɬɟɪɚɯ. Ɇɧɨɝɢɟ ɪɚɡɪɚɛɨɬɱɢɤɢ ɧɚɫɬɨɥɶɤɨ ɭɫɩɟɲɧɨ ɨɫɜɨɢɥɢ ɷɤɫɩɥɭɚɬɚɰɢɸ ɫɨɛɫɬɜɟɧɧɵɯ ɢɧɫɬɚɥɥɹɰɢɣ MySQL, ɱɬɨ ɢɦɟɸɬ ɜɨɡɦɨɠɧɨɫɬɶ ɪɚɛɨɬɚɬɶ ɞɨɦɚ ɢɥɢ ɜ ɞɨɪɨɝɟ, ɢɫɩɨɥɶɡɭɹ ɥɸɛɭɸ ɩɪɟɞɩɨɱɢɬɚɟɦɭɸ ɢɦɢ ɨɩɟɪɚɰɢɨɧɧɭɸ ɫɢɫɬɟɦɭ. Ʉɪɨɦɟ ɬɨɝɨ, ɪɭɤɨɜɨɞɢɬɟɥɢ ɝɪɭɩɩ ɪɚɡɪɚɛɨɬɱɢɤɨɜ ɱɚɫɬɨ ɪɟɤɨɦɟɧɞɭɸɬ ɫɜɨɢɦ ɩɨɞɱɢɧɟɧɧɵɦ ɢɫɩɨɥɶɡɨɜɚɬɶ ɨɬɞɟɥɶɧɵɟ ɥɨɤɚɥɶɧɵɟ ɢɧɫɬɚɥɥɹɰɢɢ MySQL, ɞɥɹ ɬɨɝɨ ɱɬɨɛɵ ɧɟ ɜɨɡɧɢɤɚɥɢ ɩɪɟɞɩɨɫɵɥɤɢ ɧɚɪɭɲɟɧɢɹ ɪɚɛɨɬɵ ɜɫɟɣ ɝɪɭɩɩɵ ɪɚɡɪɚɛɨɬɱɢɤɨɜ ɢɡ-ɡɚ ɨɬɤɚɡɚ ɜ ɟɞɢɧɫɬɜɟɧɧɨɦ ɦɟɫɬɟ. Ⱥ ɜɨ ɦɧɨɝɢɯ ɩɪɨɟɤɬɚɯ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ ɧɚ ɨɫɧɨɜɟ PHP ɤɨ ɜɫɟɦ ɪɚɡɪɚɛɨɬɱɢɤɚɦ, ɠɟɥɚɸɳɢɦ ɩɪɢɧɹɬɶ ɭɱɚɫɬɢɟ ɜ ɪɚɛɨɬɟ, ɩɪɟɞɴɹɜɥɹɟɬɫɹ ɬɪɟɛɨɜɚɧɢɟ — ɩɪɨɞɟɦɨɧɫɬɪɢɪɨɜɚɬɶ ɢɫɱɟɪɩɵɜɚɸɳɟɟ ɜɥɚɞɟɧɢɟ ɧɚɜɵɤɚɦɢ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ ɛɚɡɵ ɞɚɧɧɵɯ MySQL. Ʌɸɛɨɣ ɪɚɡɪɚɛɨɬɱɢɤ, ɪɚɛɨɬɚɸɳɢɣ ɜ ɫɪɟɞɟ PHP, ɜɩɨɥɧɟ ɫɩɨɫɨɛɟɧ ɫɚɦɨɫɬɨɹɬɟɥɶɧɨ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɬɶ ɛɚɡɭ ɞɚɧɧɵɯ MySQL, ɜ ɨɬɥɢɱɢɟ ɨɬ ɧɟɤɨɬɨɪɵɯ ɞɪɭɝɢɯ ɛɚɡ ɞɚɧɧɵɯ. Ⱦɥɹ ɬɨɝɨ ɱɬɨɛɵ ɟɳɟ ɛɨɥɶɲɟ ɭɩɪɨɫɬɢɬɶ ɡɚɞɚɱɭ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ, ɦɨɠɧɨ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɦɧɨɝɨɱɢɫɥɟɧɧɵɦɢ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɦɢ ɫɪɟɞɫɬɜɚɦɢ, ɤɨɬɨɪɵɟ ɧɟ ɬɨɥɶɤɨ ɩɪɟɞɭɫɦɨɬɪɟɧɵ ɜ ɫɚɦɨɣ ɛɚɡɟ ɞɚɧɧɵɯ MySQL, ɧɨ ɢ ɦɨɝɭɬ ɛɵɬɶ ɩɨɥɭɱɟɧɵ ɨɬ ɫɬɨɪɨɧɧɢɯ ɪɚɡɪɚɛɨɬɱɢɤɨɜ. Ʉ ɬɨɦɭ ɠɟ, ɱɬɨɛɵ ɢɦɟɬɶ ɜɨɡɦɨɠɧɨɫɬɶ ɢɧɫɬɚɥɥɢɪɨɜɚɬɶ, ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶ ɢ ɨɬɥɚɠɢɜɚɬɶ Web-ɩɪɢɥɨɠɟɧɢɹ ɜ ɫɨɫɬɚɜɟ ɦɧɨɝɢɯ ɩɪɢɤɥɚɞɧɵɯ ɩɚɤɟɬɨɜ ɧɚ ɨɫɧɨɜɟ PHP, ɧɟ ɬɨɥɶɤɨ ɤɨɦɦɟɪɱɟɫɤɢɯ, ɧɨ ɢ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ, ɧɟɨɛɯɨ- ÃËÀÂÀ 14  ýòîé ãëàâå... Ëèöåíçèðîâàíèå MySQL Èíñòàëëÿöèÿ ïðîãðàììíîãî îáåñïå÷åíèÿ MySQL: ïåðåõîä íà âåðñèþ 4 Àäìèíèñòðèðîâàíèå ó÷åòíûõ çàïèñåé MySQL Ïðîãðàììà PHPMyAdmin Ñîçäàíèå ðåçåðâíûõ êîïèé Ðåïëèêàöèÿ Âîññòàíîâëåíèå Ðåçþìå ɞɢɦɨ ɨɫɜɨɢɬɶ ɪɚɛɨɬɭ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ MySQL. ɉɨɷɬɨɦɭ ɨɫɜɨɟɧɢɟ ɧɚɜɵɤɨɜ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ MySQL ɩɪɢɧɟɫɟɬ ɱɢɬɚɬɟɥɸ ɛɨɥɶɲɭɸ ɩɨɥɶɡɭ, ɞɚɠɟ ɟɫɥɢ ɨɧ ɧɟ ɫɨɛɢɪɚɟɬɫɹ ɫɚɦɨɫɬɨɹɬɟɥɶɧɨ ɡɚɧɢɦɚɬɶɫɹ ɪɚɡɪɚɛɨɬɤɨɣ ɜɫɟɝɨ ɧɟɨɛɯɨɞɢɦɨɝɨ ɟɦɭ ɤɨɞɚ PHP. Ëèöåíçèðîâàíèå MySQL ɉɪɟɠɞɟ ɱɟɦ ɢɧɫɬɚɥɥɢɪɨɜɚɬɶ ɤɚɤɭɸ-ɥɢɛɨ ɱɚɫɬɶ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ, ɧɟɨɛɯɨɞɢɦɨ ɬɳɚɬɟɥɶɧɨ ɢɡɭɱɢɬɶ ɜɫɟ ɫɜɹɡɚɧɧɵɟ ɫ ɷɬɢɦ ɜɨɩɪɨɫɵ ɥɢɰɟɧɡɢɪɨɜɚɧɢɹ. ɗɬɨ ɬɪɟɛɨɜɚɧɢɟ ɹɜɥɹɟɬɫɹ ɨɫɨɛɟɧɧɨ ɜɚɠɧɵɦ ɜ ɨɬɧɨɲɟɧɢɢ ɬɚɤɢɯ ɩɪɨɝɪɚɦɦɧɵɯ ɩɪɨɞɭɤɬɨɜ, ɤɚɤ MySQL, ɤɨɬɨɪɵɟ ɢɦɟɸɬ ɞɜɨɣɧɵɟ ɥɢɰɟɧɡɢɢ — ɢ ɧɚ ɤɨɦɦɟɪɱɟɫɤɭɸ ɩɪɨɝɪɚɦɦɭ, ɢ ɧɚ ɩɪɨɝɪɚɦɦɭ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ. Ʉ ɫɨɠɚɥɟɧɢɸ, ɤɨ ɜɪɟɦɟɧɢ ɧɚɩɢɫɚɧɢɹ ɞɚɧɧɨɣ ɤɧɢɝɢ ɩɪɚɜɢɥɚ ɥɢɰɟɧɡɢɪɨɜɚɧɢɹ MySQL ɩɟɪɟɫɦɚɬɪɢɜɚɥɢɫɶ, ɩɨɷɬɨɦɭ ɧɚ ɜɪɟɦɹ ɜɨɡɧɢɤɚɥɢ ɧɟɫɨɜɦɟɫɬɢɦɨɫɬɢ ɫ ɥɢɰɟɧɡɢɟɣ PHP. Ⱦɨ ɬɟɯ ɩɨɪ, ɩɨɤɚ ɬɚɤɚɹ ɫɢɬɭɚɰɢɹ ɧɟ ɪɚɡɪɟɲɢɬɫɹ ɨɤɨɧɱɚɬɟɥɶɧɨ, ɪɚɡɪɚɛɨɬɱɢɤɢ, ɢɫɩɨɥɶɡɭɸɳɢɟ ɹɡɵɤ PHP, ɞɨɥɠɧɵ ɫɨɛɥɸɞɚɬɶ ɩɪɟɞɟɥɶɧɭɸ ɨɫɬɨɪɨɠɧɨɫɬɶ, ɱɬɨɛɵ ɨɛɟɫɩɟɱɢɬɶ ɫɨɛɥɸɞɟɧɢɟ ɜɫɟɯ ɥɢɰɟɧɡɢɣ. Ɍɚɤɚɹ ɡɚɞɚɱɚ ɟɳɟ ɛɨɥɶɲɟ ɭɫɥɨɠɧɹɟɬɫɹ ɞɥɹ ɬɟɯ ɪɚɡɪɚɛɨɬɱɢɤɨɜ, ɤɨɬɨɪɵɟ ɪɚɫɩɪɨɫɬɪɚɧɹɸɬ (ɚ ɧɟ ɩɪɨɫɬɨ ɢɫɩɨɥɶɡɭɸɬ) ɛɚɡɭ ɞɚɧɧɵɯ MySQL ɜ ɫɨɫɬɚɜɟ ɤɨɦɦɟɪɱɟɫɤɨɝɨ ɩɪɨɝɪɚɦɦɧɨɝɨ ɩɪɨɞɭɤɬɚ ɢɥɢ ɩɪɨɝɪɚɦɦɵ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ. ȼ ɧɟɤɨɬɨɪɵɯ ɢɡ ɩɨɫɥɟɞɧɢɯ ɜɵɩɭɫɤɨɜ PHP4 ɜ ɩɨɫɬɚɜɤɭ PHP ɜɯɨɞɢɥɢ ɤɥɢɟɧɬɫɤɢɟ ɛɢɛɥɢɨɬɟɤɢ MySQL. Ʌɟɬɨɦ 2003 ɝɨɞɚ ɤɨɦɩɚɧɢɹ MySQL AB (ɫɨɡɞɚɬɟɥɶ ɛɚɡɵ ɞɚɧɧɵɯ MySQL) ɪɟɲɢɥɚ ɩɪɢɧɹɬɶ ɥɢɰɟɧɡɢɸ GPL (General Public License — ɨɛɳɟɞɨɫɬɭɩɧɚɹ ɥɢɰɟɧɡɢɹ) ɞɥɹ ɧɟɤɨɦɦɟɪɱɟɫɤɨɝɨ ɢɫɩɨɥɶɡɨɜɚɧɢɹ. ɗɬɚ ɫɯɟɦɚ ɥɢɰɟɧɡɢɪɨɜɚɧɢɹ ɜɨ ɦɧɨɝɢɯ ɨɬɧɨɲɟɧɢɹɯ ɹɜɥɹɟɬɫɹ ɛɨɥɟɟ ɩɪɨɫɬɨɣ ɢ ɦɟɧɟɟ ɨɝɪɚɧɢɱɢɬɟɥɶɧɨɣ ɩɨ ɫɪɚɜɧɟɧɢɸ ɫ ɩɪɢɦɟɧɹɜɲɟɣɫɹ ɪɚɧɟɟ, ɧɨ ɬɚɤɚɹ ɥɢɰɟɧɡɢɹ ɨɤɚɡɚɥɨɫɶ ɧɟɫɨɜɦɟɫɬɢɦɨɣ ɫ ɥɢɰɟɧɡɢɟɣ PHP ɜ ɫɬɢɥɟ Apache, ɩɨɷɬɨɦɭ ɝɪɭɩɩɚ ɪɚɡɪɚɛɨɬɱɢɤɨɜ PHP Group ɩɨɫɱɢɬɚɥɚ ɫɟɛɹ ɧɟ ɜɩɪɚɜɟ ɢ ɞɚɥɶɲɟ ɪɚɫɩɪɨɫɬɪɚɧɹɬɶ ɛɢɛɥɢɨɬɟɤɢ ɷɬɨɣ ɛɚɡɵ ɞɚɧɧɵɯ. Ʉɨ ɜɪɟɦɟɧɢ ɜɵɯɨɞɚ ɞɚɧɧɨɣ ɤɧɢɝɢ ɢɡ ɩɟɱɚɬɢ ɭɤɚɡɚɧɧɵɣ ɜɨɩɪɨɫ ɛɵɥ ɧɚ ɷɬɚɩɟ ɨɛɨɸɞɧɨɝɨ ɫɨɝɥɚɫɨɜɚɧɢɹ, ɱɬɨ ɞɨɥɠɧɨ ɛɵɥɨ ɩɨɡɜɨɥɢɬɶ ɪɚɫɩɪɨɫɬɪɚɧɹɬɶ ɛɟɫɩɥɚɬɧɨ ɪɟɡɭɥɶɬɚɬɵ “ɫɨɜɦɟɫɬɧɵɯ ɪɚɛɨɬ” ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ, ɧɨ ɱɢɬɚɬɟɥɶ ɜɫɟ ɪɚɜɧɨ ɞɨɥɠɟɧ ɩɪɨɜɟɪɢɬɶ, ɡɚɤɪɵɬ ɥɢ ɨɤɨɧɱɚɬɟɥɶɧɨ ɞɚɧɧɵɣ ɜɨɩɪɨɫ, ɱɬɨɛɵ ɧɟ ɢɦɟɬɶ ɧɢɤɚɤɢɯ ɫɨɦɧɟɧɢɣ ɧɚ ɷɬɨɬ ɫɱɟɬ. Ɉɤɨɧɱɚɬɟɥɶɧɵɟ ɫɜɟɞɟɧɢɹ ɨ ɥɢɰɟɧɡɢɪɨɜɚɧɢɢ MySQL ɦɨɠɧɨ ɧɚɣɬɢ ɩɨ ɚɞɪɟɫɭ www.mysql.com/doc/en/ Licensing_and_Support.html. ɉɪɚɜɢɥɚ ɥɢɰɟɧɡɢɪɨɜɚɧɢɹ ɢɦɟɸɬ ɨɬɞɟɥɶɧɵɟ ɪɚɡɞɟɥɵ ɞɥɹ ɤɨɦɦɟɪɱɟɫɤɨɝɨ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɢ ɞɥɹ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɥɢɰɟɧɡɢɟɣ GPL, ɢ ɷɬɢ ɞɜɚ ɜɚɪɢɚɧɬɚ ɩɪɢɦɟɧɟɧɢɹ MySQL, ɩɨ-ɜɢɞɢɦɨɦɭ, ɹɜɥɹɸɬɫɹ ɧɚɢɛɨɥɟɟ ɩɨɞɯɨɞɹɳɢɦɢ ɞɥɹ ɛɨɥɶɲɢɧɫɬɜɚ ɪɚɡɪɚɛɨɬɱɢɤɨɜ, ɢɫɩɨɥɶɡɭɸɳɢɯ ɹɡɵɤ PHP. ɉɪɟɠɞɟ ɱɟɦ ɩɪɢɫɬɭɩɢɬɶ ɤ ɪɚɡɜɟɪɬɵɜɚɧɢɸ ɛɚɡɵ ɞɚɧɧɵɯ MySQL, ɧɟɨɛɯɨɞɢɦɨ ɜɧɢɦɚɬɟɥɶɧɨ ɩɪɨɱɢɬɚɬɶ ɥɢɰɟɧɡɢɸ. ɇɢɠɟ ɨɩɢɫɚɧɵ ɧɟɤɨɬɨɪɵɟ ɲɢɪɨɤɨ ɪɚɫɩɪɨɫɬɪɚɧɟɧɧɵɟ ɤɨɧɮɢɝɭɪɚɰɢɢ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ, ɞɥɹ ɤɨɬɨɪɵɯ ɦɨɠɟɬ ɢɦɟɬɶ ɡɧɚɱɟɧɢɟ ɧɨɜɚɹ ɫɯɟɦɚ ɥɢɰɟɧɡɢɪɨɜɚɧɢɹ MySQL. ɉɪɢɦɟɧɟɧɢɟ ɢɫɤɥɸɱɢɬɟɥɶɧɨ ɜ ɫɨɫɬɚɜɟ Web-ɭɡɥɚ. ȿɫɥɢ ɛɚɡɚ ɞɚɧɧɵɯ MySQL ɷɤɫɩɥɭɚɬɢɪɭɟɬɫɹ ɢɫɤɥɸɱɢɬɟɥɶɧɨ ɤɚɤ ɱɚɫɬɶ ɤɨɦɦɟɪɱɟɫɤɨɝɨ ɢɥɢ ɧɟɤɨɦɦɟɪɱɟɫɤɨɝɨ Web-ɭɡɥɚ, ɬɨ ɟɟ ɦɨɠɧɨ ɩɪɨɞɨɥɠɚɬɶ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶ, ɧɟ ɡɚɞɭɦɵɜɚɹɫɶ ɨ ɩɪɨɛɥɟɦɚɯ ɥɢɰɟɧɡɢɪɨɜɚɧɢɹ. ȼ ɬɚɤɨɦ ɫɥɭɱɚɟ ɤɨɦɩɚɧɢɹ MySQL AB ɩɪɟɞɥɚɝɚɟɬ ɥɢɲɶ ɡɚɤɥɸɱɢɬɶ ɤɨɧɬɪɚɤɬ ɧɚ ɫɨɩɪɨɜɨɠɞɟɧɢɟ, ɩɨɡɜɨɥɹɸɳɢɣ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɪɟɡɭɥɶɬɚɬɚɦɢ ɞɚɥɶɧɟɣɲɢɯ ɪɚɡɪɚɛɨɬɨɤ. ɉɪɨɟɤɬ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ, ɪɚɡɪɚɛɚɬɵɜɚɟɦɵɣ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɥɢɰɟɧɡɢɟɣ GPL. ȿɫɥɢ ɜɵ ɪɚɫɩɪɨɫɬɪɚɧɹɟɬɟ ɫɟɪɜɟɪ ɢɥɢ ɤɥɢɟɧɬɫɤɢɟ ɛɢɛɥɢɨɬɟɤɢ MySQL ɜ ɫɨɫɬɚɜɟ ɩɪɨɟɤɬɚ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ, ɜɵɩɭɳɟɧɧɨɝɨ ɩɨ ɜɫɟɦ ɩɪɚɜɢɥɚɦ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɥɢɰɟɧɡɢɟɣ GNU General Public License, ɬɨ ɦɨɠɟɬɟ (ɢ ɞɚɠɟ ɨɛɹɡɚɧɵ) ɪɚɫɩɪɨɫɬɪɚɧɹɬɶ ɩɪɨɝɪɚɦɦɧɵɣ ɩɪɨɞɭɤɬ MySQL ɢ ɟɝɨ ɢɫɯɨɞɧɵɣ ɤɨɞ ɛɟɫɩɥɚɬɧɨ. 346 ×àñòü II. PHP è MySQL Ʉɨɦɦɟɪɱɟɫɤɚɹ ɩɨɫɬɚɜɤɚ. ȿɫɥɢ ɜɵ ɪɚɫɩɪɨɫɬɪɚɧɹɟɬɟ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ ɫɟɪɜɟɪɚ ɢɥɢ ɤɥɢɟɧɬɫɤɢɟ ɛɢɛɥɢɨɬɟɤɢ MySQL ɜ ɫɨɫɬɚɜɟ ɤɨɦɦɟɪɱɟɫɤɨɝɨ ɩɪɨɝɪɚɦɦɧɨɝɨ ɩɪɨɞɭɤɬɚ, ɬɨ ɨɛɹɡɚɧɵ ɩɪɢɨɛɪɟɫɬɢ ɤɨɦɦɟɪɱɟɫɤɭɸ ɥɢɰɟɧɡɢɸ ɜ ɤɨɦɩɚɧɢɢ MySQL AB. ɉɪɨɟɤɬ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ, ɪɚɡɪɚɛɚɬɵɜɚɟɦɵɣ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɥɢɰɟɧɡɢɟɣ, ɨɬɥɢɱɧɨɣ ɨɬ GPL. ȼ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɬɚɤɚɹ ɫɢɬɭɚɰɢɹ ɦɨɠɟɬ ɜ ɩɪɢɧɰɢɩɟ ɫɬɚɬɶ ɢɫɬɨɱɧɢɤɨɦ ɩɪɨɛɥɟɦ, ɩɨɫɤɨɥɶɤɭ ɩɨɫɥɟ ɜɜɨɞɚ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ ɫɟɪɜɟɪɚ ɢɥɢ ɤɥɢɟɧɬɫɤɢɯ ɛɢɛɥɢɨɬɟɤ MySQL ɜ ɫɨɫɬɚɜ ɩɪɨɟɤɬɚ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ, ɧɚ ɤɨɬɨɪɵɣ ɧɟ ɪɚɫɩɪɨɫɬɪɚɧɹɟɬɫɹ ɥɢɰɟɧɡɢɹ GPL, ɦɨɠɟɬ ɨɤɚɡɚɬɶɫɹ, ɱɬɨ ɜɚɲ ɤɨɞ ɩɨɞɥɟɠɢɬ ɥɢɰɟɧɡɢɪɨɜɚɧɢɸ ɫɨɝɥɚɫɧɨ GPL. ɉɪɨɫɦɨɬɪɢɬɟ ɫɬɪɚɧɢɰɭ ɫ ɩɪɚɜɢɥɚɦɢ ɥɢɰɟɧɡɢɪɨɜɚɧɢɹ MySQL, ɱɬɨɛɵ ɩɨɥɭɱɢɬɶ ɧɚɢɛɨɥɟɟ ɚɤɬɭɚɥɶɧɭɸ ɢɧɮɨɪɦɚɰɢɸ ɨ ɬɨɦ, ɤɚɤɨɣ ɫɬɚɬɭɫ ɞɨɥɠɧɚ ɢɦɟɬɶ ɛɚɡɚ ɞɚɧɧɵɯ MySQL ɩɨ ɨɬɧɨɲɟɧɢɸ ɤ ɜɚɲɟɦɭ ɩɪɨɟɤɬɭ. ɇɨ ɫɥɟɞɭɟɬ ɭɱɢɬɵɜɚɬɶ, ɱɬɨ ɩɨɞɨɛɧɵɯ ɨɝɪɚɧɢɱɟɧɢɣ, ɫɜɹɡɚɧɧɵɯ ɫ ɥɢɰɟɧɡɢɪɨɜɚɧɢɟɦ, ɜɨ ɦɧɨɝɢɯ ɫɥɭɱɚɹɯ ɦɨɠɧɨ ɥɟɝɤɨ ɢɡɛɟɠɚɬɶ. Ⱦɥɹ ɷɬɨɝɨ ɧɟɨɛɯɨɞɢɦɨ ɩɪɟɤɪɚɬɢɬɶ ɫɚɦɨɦɭ ɩɨɫɬɚɜɥɹɬɶ ɛɚɡɭ ɞɚɧɧɵɯ ɢ ɩɨɬɪɟɛɨɜɚɬɶ ɨɬ ɩɨɥɶɡɨɜɚɬɟɥɟɣ, ɱɬɨɛɵ ɨɧɢ ɩɪɢɨɛɪɟɬɚɥɢ ɢ ɭɫɬɚɧɚɜɥɢɜɚɥɢ MySQL ɫɚɦɨɫɬɨɹɬɟɥɶɧɨ. Èíñòàëëÿöèÿ ïðîãðàììíîãî îáåñïå÷åíèÿ MySQL: ïåðåõîä íà âåðñèþ 4 ɋɥɟɞɭɟɬ ɭɱɢɬɵɜɚɬɶ, ɱɬɨ ɫɟɪɜɟɪ ɢ ɤɥɢɟɧɬɫɤɢɟ ɛɢɛɥɢɨɬɟɤɢ MySQL ɧɟɨɛɯɨɞɢɦɨ ɢɧɫɬɚɥɥɢɪɨɜɚɬɶ ɩɟɪɟɞ ɢɧɫɬɚɥɥɹɰɢɟɣ PHP! Ȼɟɡɭɫɥɨɜɧɨ, ɷɬɨ ɬɪɟɛɨɜɚɧɢɟ ɧɟ ɹɜɥɹɟɬɫɹ ɫɬɪɨɝɨ ɨɛɹɡɚɬɟɥɶɧɵɦ ɜɨ ɜɫɟɯ ɨɛɫɬɨɹɬɟɥɶɫɬɜɚɯ, ɨɫɨɛɟɧɧɨ ɟɫɥɢ ɪɟɱɶ ɢɞɟɬ ɨ ɫɢɫɬɟɦɟ Windows, ɧɨ ɩɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ PHP ɜɫɟɝɞɚ ɪɟɤɨɦɟɧɞɭɟɬɫɹ ɨɛɟɫɩɟɱɢɬɶ ɢɧɫɬɚɥɥɹɰɢɸ ɞɨɥɠɧɵɦ ɨɛɪɚɡɨɦ ɜɫɟɯ ɫɟɪɜɟɪɨɜ ɢ ɛɢɛɥɢɨɬɟɤ ɫɬɨɪɨɧɧɢɯ ɪɚɡɪɚɛɨɬɱɢɤɨɜ ɢ ɬɨɥɶɤɨ ɩɨɫɥɟ ɷɬɨɝɨ ɡɚɧɢɦɚɬɶɫɹ ɧɚɫɬɪɨɣɤɨɣ ɫɢɫɬɟɦɵ PHP ɞɥɹ ɨɛɟɫɩɟɱɟɧɢɹ ɫɜɹɡɢ ɫ ɷɬɢɦɢ ɩɪɨɝɪɚɦɦɚɦɢ. Ïðîáëåìû, êîòîðûå äîëæíû áûòü ðåøåíû äî íà÷àëà èíñòàëëÿöèè ȼ ɬɟɱɟɧɢɟ ɩɪɨɞɨɥɠɢɬɟɥɶɧɨɝɨ ɜɪɟɦɟɧɢ ɛɵɥɚ ɞɨɫɬɭɩɧɚ ɬɨɥɶɤɨ ɜɟɪɫɢɹ MySQL 3, ɢ ɡɚ ɷɬɨɬ ɩɟɪɢɨɞ ɦɧɨɝɢɟ ɪɚɡɪɚɛɨɬɱɢɤɢ PHP ɧɚɭɱɢɥɢɫɶ ɭɫɩɟɲɧɨ ɟɟ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶ. ɇɨ ɜ ɜɟɪɫɢɢ MySQL 4 ɛɵɥɢ ɜɧɟɫɟɧɵ ɧɟɤɨɬɨɪɵɟ ɞɨɩɨɥɧɟɧɢɹ ɢ ɢɡɦɟɧɟɧɢɹ, ɤɚɤ ɫɨ ɫɬɨɪɨɧɵ ɛɚɡɵ ɞɚɧɧɵɯ, ɬɚɤ ɢ ɫɨ ɫɬɨɪɨɧɵ PHP. ɉɨɷɬɨɦɭ ɢ ɧɚɱɢɧɚɸɳɢɟ, ɢ ɨɩɵɬɧɵɟ ɪɚɡɪɚɛɨɬɱɢɤɢ Web ɞɨɥɠɧɵ ɧɚɣɬɢ ɜɪɟɦɹ, ɱɬɨɛɵ ɨɡɧɚɤɨɦɢɬɶɫɹ ɫ ɷɬɢɦɢ ɢɡɦɟɧɟɧɢɹɦɢ. Ⱦɚɠɟ ɫɩɟɰɢɚɥɢɫɬ, ɤɨɬɨɪɵɣ ɢɦɟɟɬ ɛɨɥɶɲɨɣ ɨɩɵɬ ɪɚɛɨɬɵ ɫ ɜɟɪɫɢɟɣ MySQL 3, ɧɟ ɞɨɥɠɟɧ ɪɚɫɫɱɢɬɵɜɚɬɶ ɧɚ ɬɨ, ɱɬɨ ɫɭɦɟɟɬ ɢɧɫɬɚɥɥɢɪɨɜɚɬɶ ɢ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶ ɜɟɪɫɢɸ MySQL 4, ɢɫɩɨɥɶɡɭɹ ɬɨɱɧɨ ɬɚɤɢɟ ɠɟ ɩɪɨɰɟɞɭɪɵ, ɤɚɤ ɢ ɩɪɟɠɞɟ. ɉɟɪɟɞ ɬɟɦ ɤɚɤ ɩɪɢɫɬɭɩɚɬɶ ɤ ɢɧɫɬɚɥɥɹɰɢɢ ɧɨɜɵɯ ɜɟɪɫɢɣ MySQL ɢ PHP, ɧɟɨɛɯɨɞɢɦɨ ɨɡɧɚɤɨɦɢɬɶɫɹ ɫ ɬɪɟɦɹ ɜɚɠɧɵɦɢ ɜɨɩɪɨɫɚɦɢ, ɨɬɧɨɫɹɳɢɦɢɫɹ ɤ MySQL: ɧɨɜɵɟ ɢ ɧɟɫɨɜɦɟɫɬɢɦɵɟ ɫɨ ɫɬɚɪɵɦɢ ɤɥɢɟɧɬɫɤɢɟ ɛɢɛɥɢɨɬɟɤɢ, ɧɨɜɨɟ ɪɚɫɲɢɪɟɧɢɟ mysqli ɫɢɫɬɟɦɵ PHP ɢ ɧɨɜɵɟ ɬɢɩɵ ɬɚɛɥɢɰ, ɤɨɬɨɪɵɟ ɨɛɟɫɩɟɱɢɜɚɸɬ ɬɪɚɧɡɚɤɰɢɨɧɧɭɸ ɩɨɞɞɟɪɠɤɭ. Примечание ɉɨɞ ɬɪɚɧɡɚɤɰɢɨɧɧɨɣ ɩɨɞɞɟɪɠɤɨɣ ɩɨɞɪɚɡɭɦɟɜɚɟɬɫɹ ɫɩɨɫɨɛɧɨɫɬɶ ɨɛɪɚɛɚɬɵɜɚɬɶ ɝɪɭɩɩɭ ɨɩɟɪɚɰɢɣ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ ɤɚɤ ɨɬɞɟɥɶɧɭɸ ɟɞɢɧɢɰɭ ɪɚɛɨɬɵ, ɫ ɬɨɱɤɢ ɡɪɟɧɢɹ ɬɨɝɨ, ɞɨɥɠɧɵ ɥɢ ɛɵɬɶ ɩɪɢɧɹɬɵ ɢɥɢ ɨɬɜɟɪɝɧɭɬɵ ɞɚɧɧɵɟ, ɤɨɬɨɪɵɟ ɜɜɨɞɹɬɫɹ ɢɥɢ ɦɨɞɢɮɢɰɢɪɭɸɬɫɹ ɫ ɩɨɦɨɳɶɸ ɜɫɟɯ ɷɬɢɯ ɨɩɟɪɚɰɢɣ. ɇɚɩɪɢɦɟɪ, ɬɪɚɧɡɚɤɰɢɹ ɜ ɫɢɫɬɟɦɟ ɷɥɟɤɬɪɨɧɧɨɣ ɬɨɪɝɨɜɥɢ ɦɨɠɟɬ ɫɨɫɬɨɹɬɶ ɢɡ ɧɟɫɤɨɥɶɤɢɯ ɷɬɚɩɨɜ ɢ ɡɚɬɪɚɝɢɜɚɬɶ ɦɧɨɝɨ ɪɚɡɧɵɯ ɬɚɛɥɢɰ. ɉɪɟɞɩɨɥɨɠɢɦ, ɱɬɨ ɜɧɚɱɚɥɟ ɪɟɝɢɫɬɪɢɪɭɟɬɫɹ ɧɨɜɵɣ ɩɨɥɶɡɨɜɚɬɟɥɶ, Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 347 ɩɪɨɢɫɯɨɞɢɬ ɩɨɥɭɱɟɧɢɟ ɢɧɮɨɪɦɚɰɢɢ ɨɛ ɨɩɥɚɬɟ ɢ ɩɨɫɬɚɜɤɟ, ɨɬɦɟɱɚɟɬɫɹ ɭɦɟɧɶɲɟɧɢɟ ɡɚɩɚɫɚ ɬɨɜɚɪɨɜ ɧɚ ɫɤɥɚɞɟ ɢ ɬ.ɞ. ɇɨ ɜɫɟ ɷɬɢ ɢɡɦɟɧɟɧɢɹ ɧɟ ɞɨɥɠɧɵ ɛɵɬɶ ɜɧɟɫɟɧɵ ɜ ɛɚɡɭ ɞɚɧɧɵɯ ɞɨ ɬɟɯ ɩɨɪ, ɩɨɤɚ ɧɟ ɩɪɨɢɡɨɣɞɟɬ ɭɫɩɟɲɧɨɟ ɫɩɢɫɚɧɢɟ ɞɟɧɟɠɧɵɯ ɫɪɟɞɫɬɜ ɫ ɤɪɟɞɢɬɧɨɣ ɤɚɪɬɨɱɤɢ, ɞɚɠɟ ɟɫɥɢ ɤɚɠɞɵɣ ɢɡ ɩɪɟɞɵɞɭɳɢɯ ɷɬɚɩɨɜ ɩɪɨɰɟɫɫɚ ɩɨɤɭɩɤɢ ɛɭɞɟɬ ɜɵɩɨɥɧɟɧ ɭɫɩɟɲɧɨ. ȼ ɬɚɤɨɦ ɫɥɭɱɚɟ ɧɟɨɛɯɨɞɢɦɨ ɢɦɟɬɶ ɬɪɚɧɡɚɤɰɢɨɧɧɭɸ ɛɚɡɭ ɞɚɧɧɵɯ, ɤɨɬɨɪɚɹ ɩɨɡɜɨɥɹɟɬ ɨɬɫɥɟɠɢɜɚɬɶ ɜɫɟ ɢɡɦɟɧɟɧɢɹ ɞɚɧɧɵɯ, ɩɪɨɢɫɯɨɞɹɳɢɟ ɜ ɩɪɨɰɟɫɫɟ ɨɮɨɪɦɥɟɧɢɹ ɩɨɤɭɩɤɢ, ɩɨɫɥɟ ɱɟɝɨ ɥɢɛɨ ɮɢɤɫɢɪɨɜɚɬɶ ɜɫɟ ɷɬɢ ɢɡɦɟɧɟɧɢɹ ɜ ɜɢɞɟ ɨɞɧɨɣ ɟɞɢɧɢɰɵ ɪɚɛɨɬɵ, ɥɢɛɨ ɜɵɩɨɥɧɹɬɶ ɨɬɤɚɬ ɜɫɟɯ ɷɬɢɯ ɢɡɦɟɧɟɧɢɣ ɤɚɤ ɨɬɞɟɥɶɧɨɣ ɟɞɢɧɢɰɵ. Ⱦɨ ɜɵɩɭɫɤɚ ɜɟɪɫɢɢ 4 ɛɚɡɚ ɞɚɧɧɵɯ MySQL ɧɟ ɛɵɥɚ ɬɪɚɧɡɚɤɰɢɨɧɧɨɣ, ɧɨ ɬɟɩɟɪɶ ɨɛɟɫɩɟɱɢɜɚɟɬ ɩɨɞɞɟɪɠɤɭ ɬɪɚɧɡɚɤɰɢɣ. Íîâûå êëèåíòñêèå áèáëèîòåêè Ʉɥɢɟɧɬɫɤɢɟ ɛɢɛɥɢɨɬɟɤɢ ɞɥɹ ɜɟɪɫɢɣ MySQL 3 ɢ 4.0 ɧɟ ɨɛɟɫɩɟɱɢɜɚɸɬ ɩɪɹɦɨɣ ɫɨɜɦɟɫɬɢɦɨɫɬɢ ɫ ɫɟɪɜɟɪɨɦ MySQL 4.1 ɢ ɩɨɫɥɟɞɭɸɳɢɯ ɜɟɪɫɢɣ. ɉɨɷɬɨɦɭ, ɟɫɥɢ ɬɪɟɛɭɟɬɫɹ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶ MySQL 4.1 ɢ ɩɨɫɥɟɞɭɸɳɢɟ ɜɟɪɫɢɢ, ɬɨ ɧɟɨɛɯɨɞɢɦɨ ɩɨɜɬɨɪɧɨ ɫɨɛɪɚɬɶ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ PHP ɫ ɧɨɜɵɦɢ ɛɢɛɥɢɨɬɟɤɚɦɢ. Ɉɛɪɚɬɧɨɟ ɭɬɜɟɪɠɞɟɧɢɟ ɧɟ ɹɜɥɹɟɬɫɹ ɢɫɬɢɧɧɵɦ, ɩɨɫɤɨɥɶɤɭ ɛɨɥɟɟ ɫɬɚɪɵɟ ɜɟɪɫɢɢ ɫɟɪɜɟɪɚ MySQL ɦɨɠɧɨ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶ ɫ ɤɥɢɟɧɬɫɤɢɦɢ ɛɢɛɥɢɨɬɟɤɚɦɢ MySQL 4.1. ɉɨɫɥɟ ɩɟɪɟɯɨɞɚ ɧɚ ɧɨɜɵɟ ɛɢɛɥɢɨɬɟɤɢ ɦɨɠɟɬ ɬɚɤɠɟ ɩɨɬɪɟɛɨɜɚɬɶɫɹ ɨɛɧɨɜɢɬɶ ɬɚɛɥɢɰɵ ɫ ɩɪɚɜɚɦɢ ɞɨɫɬɭɩɚ ɢ ɜɫɟ ɫɬɨɥɛɰɵ, ɫɨɞɟɪɠɚɳɢɟ ɯɷɲ-ɦɚɫɫɢɜɵ ɩɚɪɨɥɟɣ, ɜɵɱɢɫɥɟɧɧɵɟ ɫɢɫɬɟɦɨɣ MySQL, ɤɨɬɨɪɵɟ ɛɵɥɢ ɫɨɡɞɚɧɵ ɜ ɤɚɤɢɯ-ɥɢɛɨ ɬɚɛɥɢɰɚɯ. Ɉɫɧɨɜɧɨɟ ɪɚɡɥɢɱɢɟ ɦɟɠɞɭ ɤɥɢɟɧɬɫɤɢɦɢ ɛɢɛɥɢɨɬɟɤɚɦɢ ɤɚɫɚɟɬɫɹ ɜɨɩɪɨɫɚ ɚɭɬɟɧɬɢɮɢɤɚɰɢɢ. ɉɪɢɦɟɧɟɧɢɟ ɮɭɧɤɰɢɢ PASSWORD()ɹɡɵɤɚ MySQL ɪɚɧɶɲɟ ɩɪɢɜɨɞɢɥɨ ɤ ɩɨɥɭɱɟɧɢɸ 16ɛɚɣɬɨɜɨɝɨ ɯɷɲ-ɦɚɫɫɢɜɚ. ɇɚɱɢɧɚɹ ɫ 4.1.1 ɢ ɩɨɫɥɟɞɭɸɳɢɯ ɜɟɪɫɢɣ, ɩɪɢɦɟɧɟɧɢɟ ɷɬɨɣ ɮɭɧɤɰɢɢ ɩɪɢɜɨɞɢɬ ɤ ɩɨɥɭɱɟɧɢɸ 41-ɛɚɣɬɨɜɨɝɨ ɯɷɲ-ɦɚɫɫɢɜɚ. ȼ ɫɢɫɬɟɦɟ MySQL ɮɭɧɤɰɢɹ PASSWORD() ɢɫɩɨɥɶɡɭɟɬɫɹ ɞɥɹ ɭɫɬɚɧɨɜɤɢ ɫɨɛɫɬɜɟɧɧɵɯ ɫɯɟɦ ɨɩɪɟɞɟɥɟɧɢɹ ɩɪɚɜ ɞɨɫɬɭɩɚ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɷɬɨɣ ɫɢɫɬɟɦɵ, ɩɨɷɬɨɦɭ ɧɟɨɛɯɨɞɢɦɨ ɨɛɧɨɜɢɬɶ ɬɚɛɥɢɰɵ ɩɪɚɜ ɞɨɫɬɭɩɚ ɜ ɜɟɪɫɢɹɯ MySQL, ɩɪɟɞɲɟɫɬɜɭɸɳɢɯ 4.1.1, ɫ ɩɨɦɨɳɶɸ ɫɰɟɧɚɪɢɹ mysql_fix_privilege_tables. ɇɟ ɢɫɤɥɸɱɟɧɚ ɬɚɤɠɟ ɜɨɡɦɨɠɧɨɫɬɶ, ɱɬɨ ɩɨɬɪɟɛɭɟɬɫɹ ɢɡɦɟɧɢɬɶ ɜɪɭɱɧɭɸ ɜ ɞɪɭɝɢɯ ɬɚɛɥɢɰɚɯ ɯɚɪɚɤɬɟɪɢɫɬɢɤɢ ɫɬɨɥɛɰɨɜ, ɜ ɤɨɬɨɪɵɟ ɜɜɨɞɹɬɫɹ ɜɵɯɨɞɧɵɟ ɞɚɧɧɵɟ ɢɡ ɮɭɧɤɰɢɢ PASSWORD() ɫɢɫɬɟɦɵ MySQL, ɞɥɹ ɬɨɝɨ ɱɬɨɛɵ ɨɧɢ ɢɦɟɥɢ ɞɥɢɧɭ 41 ɛɚɣɬ. Ɏɚɤɬɢɱɟɫɤɨɟ ɫɨɞɟɪɠɢɦɨɟ ɷɬɢɯ ɫɬɨɥɛɰɨɜ ɢɡɦɟɧɹɬɶ ɧɟ ɬɪɟɛɭɟɬɫɹ (ɜɟɪɫɢɹ MySQL 4.1 ɩɪɨɞɨɥɠɚɟɬ ɩɪɢɧɢɦɚɬɶ ɯɷɲ-ɦɚɫɫɢɜɵ ɤɨɪɨɱɟ 41 ɛɚɣɬɚ), ɧɨ ɪɚɡɦɟɪɵ ɫɬɨɥɛɰɨɜ ɞɨɥɠɧɵ ɛɵɬɶ ɭɜɟɥɢɱɟɧɵ, ɞɥɹ ɬɨɝɨ ɱɬɨɛɵ ɜ ɧɢɯ ɦɨɠɧɨ ɛɵɥɨ ɡɚɩɢɫɵɜɚɬɶ ɧɨɜɵɟ ɡɧɚɱɟɧɢɹ. Ðàñøèðåíèå mysqli Ȼɭɤɜɚ “i” ɜ ɧɚɡɜɚɧɢɢ ɪɚɫɲɢɪɟɧɢɹ “mysqli” ɹɜɥɹɟɬɫɹ ɫɨɤɪɚɳɟɧɢɟɦ ɨɬ improved (ɭɫɨɜɟɪɲɟɧɫɬɜɨɜɚɧɧɵɣ). ɇɨɜɨɟ ɪɚɫɲɢɪɟɧɢɟ mysqli ɞɥɹ PHP ɩɨɡɜɨɥɹɟɬ ɩɨɥɭɱɢɬɶ ɞɨɫɬɭɩ ɤ ɧɨɜɵɦ ɮɭɧɤɰɢɨɧɚɥɶɧɵɦ ɜɨɡɦɨɠɧɨɫɬɹɦ MySQL 4.1 ɢ ɩɨɫɥɟɞɭɸɳɢɯ ɜɟɪɫɢɣ, ɨɫɨɛɟɧɧɨ ɤ ɫɪɟɞɫɬɜɚɦ ɩɨɞɞɟɪɠɤɢ ɬɪɚɧɡɚɤɰɢɣ, ɤɨɬɨɪɵɟ ɨɬɧɨɫɹɬɫɹ ɤ ɱɢɫɥɭ ɧɚɢɛɨɥɟɟ ɜɚɠɧɵɯ ɧɨɜɵɯ ɜɨɡɦɨɠɧɨɫɬɟɣ MySQL 4. Внимание! Ɋɚɫɲɢɪɟɧɢɟ mysql ɦɨɠɟɬ ɩɪɢɦɟɧɹɬɶɫɹ ɬɨɥɶɤɨ ɫ ɜɟɪɫɢɹɦɢ MySQL ɧɢɠɟ 4.1, ɚ ɪɚɫɲɢɪɟɧɢɟ mysqli ɪɚɛɨɬɚɟɬ ɬɨɥɶɤɨ ɫ MySQL 4.1 ɢ ɩɨɫɥɟɞɭɸɳɢɦɢ ɜɟɪɫɢɹɦɢ. Ʉ ɫɨɠɚɥɟɧɢɸ, ɷɬɨ ɪɚɫɲɢɪɟɧɢɟ ɧɟ ɹɜɥɹɟɬɫɹ ɩɨɥɧɨɫɬɶɸ ɫɨɜɦɟɫɬɢɦɵɦ ɫɨ ɫɬɚɪɵɦ ɪɚɫɲɢɪɟɧɢɟɦ mysql ɢ ɬɟɦɢ ɮɭɧɤɰɢɹɦɢ, ɤɨɬɨɪɵɟ ɫɜɹɡɚɧɵ ɫ mysql. ɉɨɷɬɨɦɭ ɧɚ ɷɬɚɩɟ ɤɨɦɩɢɥɹɰɢɢ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ PHP ɥɭɱɲɟ ɜɫɟɝɨ ɜɵɛɪɚɬɶ ɥɢɛɨ ɬɨ, ɥɢɛɨ ɞɪɭɝɨɟ ɪɚɫɲɢɪɟɧɢɟ. Ʉɨ ɜɪɟɦɟɧɢ ɧɚɩɢɫɚɧɢɹ ɞɚɧɧɨɣ ɤɧɢɝɢ ɪɚɫɲɢɪɟɧɢɟ mysqli ɫɱɢɬɚɥɨɫɶ ɷɤɫɩɟɪɢɦɟɧɬɚɥɶɧɵɦ, ɩɨɷɬɨɦɭ, ɫɤɨɪɟɟ ɜɫɟɝɨ, ɧɟ ɞɨɥɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɧɚ ɩɪɨɢɡɜɨɞɫɬɜɟ. Ɍɟɨɪɟɬɢɱɟɫɤɢ ɜɨɡɦɨɠɧɨ ɨɬɤɨɦɩɢɥɢɪɨɜɚɬɶ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ PHP ɨɞɧɨɜɪɟɦɟɧɧɨ ɫ ɪɚɫɲɢɪɟɧɢɹɦɢ mysql ɢ mysqli (ɟɫɥɢ, ɧɚɩɪɢɦɟɪ, ɧɟɨɛɯɨɞɢɦɨ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶ ɧɚ ɨɞɧɨɦ ɢ ɬɨɦ 348 ×àñòü II. PHP è MySQL ɠɟ ɤɨɦɩɶɸɬɟɪɟ ɤɚɤɭɸ-ɬɨ ɜɟɪɫɢɸ 3.x, ɚ ɬɚɤɠɟ 4.1 ɢɥɢ ɫɥɟɞɭɸɳɭɸ ɜɟɪɫɢɸ MySQL), ɧɨ ɬɪɟɛɭɟɬɫɹ ɫɨɛɥɸɞɚɬɶ ɩɪɟɞɟɥɶɧɭɸ ɨɫɬɨɪɨɠɧɨɫɬɶ, ɱɬɨɛɵ ɢɡɛɟɠɚɬɶ ɤɨɧɮɥɢɤɬɨɜ ɦɟɠɞɭ ɤɥɢɟɧɬɫɤɢɦɢ ɛɢɛɥɢɨɬɟɤɚɦɢ. ɇɚ ɩɪɚɤɬɢɤɟ ɨɛɵɱɧɨ ɥɭɱɲɟ ɜɵɛɪɚɬɶ ɥɢɛɨ ɬɨ, ɥɢɛɨ ɞɪɭɝɨɟ ɪɚɫɲɢɪɟɧɢɟ. Внимание! ȿɫɥɢ ɜɵ ɪɟɲɢɥɢ ɨɩɪɨɛɨɜɚɬɶ ɪɚɫɲɢɪɟɧɢɟ mysqli, ɬɨ ɧɟ ɡɚɛɭɞɶɬɟ ɨɬɦɟɧɢɬɶ ɪɚɫɲɢɪɟɧɢɟ mysql, ɤɨɬɨɪɨɟ ɨɛɵɱɧɨ ɪɚɡɪɟɲɟɧɨ ɩɨ ɭɦɨɥɱɚɧɢɸ. (ȼ ɜɟɪɫɢɹɯ Unix ɢɫɩɨɥɶɡɭɣɬɟ ɞɥɹ ɷɬɨɝɨ ɨɩɰɢɸ --without-mysql, ɚ ɜ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɟ Windows ɡɚɤɨɦɦɟɧɬɢɪɭɣɬɟ ɜɵɡɨɜ ɪɚɫɲɢɪɟɧɢɹ mysql.dll ɜ ɮɚɣɥɟ php.ini.) Òàáëèöû ñ ïîääåðæêîé òðàíçàêöèé ɇɚ ɩɪɨɬɹɠɟɧɢɢ ɩɨɱɬɢ ɜɫɟɝɨ ɩɟɪɢɨɞɚ ɫɭɳɟɫɬɜɨɜɚɧɢɹ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ MySQL ɜ ɧɟɦ ɢɫɩɨɥɶɡɨɜɚɥɢɫɶ ɬɚɛɥɢɰɵ ɫɩɟɰɢɚɥɢɡɢɪɨɜɚɧɧɨɝɨ ɬɢɩɚ, ɤɨɬɨɪɵɣ ɨɛɨɡɧɚɱɚɟɬɫɹ ɤɚɤ MyISAM. ɇɚ ɩɨɫɥɟɞɧɢɯ ɷɬɚɩɚɯ ɰɢɤɥɚ ɜɵɩɭɫɤɚ ɜɟɪɫɢɣ 3.xx ɜ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ ɷɬɨɣ ɛɚɡɵ ɞɚɧɧɵɯ ɛɵɥɢ ɜɜɟɞɟɧɵ ɞɜɚ ɧɨɜɵɯ ɬɢɩɚ (ɬɚɛɥɢɰɚ ISAM ɢ heap — ɞɢɧɚɦɢɱɟɫɤɚɹ ɨɛɥɚɫɬɶ ɩɚɦɹɬɢ), ɧɨ ɨɧɢ ɧɟ ɧɚɲɥɢ ɲɢɪɨɤɨɝɨ ɪɚɫɩɪɨɫɬɪɚɧɟɧɢɹ. Ɍɚɛɥɢɰɵ ɬɢɩɚ MyISAM ɩɪɢɦɟɧɹɸɬɫɹ ɩɨ ɭɦɨɥɱɚɧɢɸ ɞɨ ɫɢɯ ɩɨɪ ɢ ɧɚɦɧɨɝɨ ɩɪɟɜɨɫɯɨɞɹɬ ɩɨ ɫɜɨɟɣ ɪɚɫɩɪɨɫɬɪɚɧɟɧɧɨɫɬɢ ɬɚɛɥɢɰɵ ɜɫɟɯ ɩɪɨɱɢɯ ɬɢɩɨɜ. ɇɨ ɞɥɹ ɩɨɞɞɟɪɠɤɢ ɬɪɚɧɡɚɤɰɢɣ ɜ MySQL 4.1 ɢ ɩɨɫɥɟɞɭɸɳɢɯ ɜɟɪɫɢɹɯ ɝɪɭɩɩɨɣ ɪɚɡɪɚɛɨɬɱɢɤɨɜ MySQL ɛɵɥɢ ɫɨɡɞɚɧɵ ɞɜɚ ɧɨɜɵɯ ɬɢɩɚ ɬɚɛɥɢɰ ɫ ɩɨɞɞɟɪɠɤɨɣ ɬɪɚɧɡɚɤɰɢɣ — InnoDB ɢ BDB. ȿɫɥɢ ɜ ɩɪɢɥɨɠɟɧɢɢ ɧɟɨɛɯɨɞɢɦɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɨɩɟɪɚɰɢɢ ɮɢɤɫɚɰɢɢ ɢ ɨɬɤɚɬɚ, ɬɨ ɫɥɟɞɭɟɬ ɨɬɤɨɦɩɢɥɢɪɨɜɚɬɶ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ MySQL ɫ ɭɱɟɬɨɦ ɫɩɨɫɨɛɧɨɫɬɢ ɪɚɫɩɨɡɧɚɜɚɬɶ ɨɞɢɧ ɢɡ ɷɬɢɯ ɬɢɩɨɜ ɢ ɨɩɪɟɞɟɥɹɬɶ ɤɚɠɞɭɸ ɬɚɛɥɢɰɭ ɤɚɤ ɬɚɛɥɢɰɭ InnoDB. Ʉɪɨɦɟ ɬɨɝɨ, ɩɪɟɞɭɫɦɨɬɪɟɧɚ ɜɨɡɦɨɠɧɨɫɬɶ ɫɨɜɦɟɫɬɧɨ ɩɪɢɦɟɧɹɬɶ ɜ ɨɞɧɨɣ ɢ ɬɨɣ ɠɟ ɛɚɡɟ ɞɚɧɧɵɯ ɬɚɛɥɢɰɵ ɪɚɡɧɵɯ ɬɢɩɨɜ, ɚ ɬɚɤɠɟ ɩɪɟɨɛɪɚɡɨɜɵɜɚɬɶ ɬɚɛɥɢɰɵ MyISAM ɜ ɬɚɛɥɢɰɵ InnoDB. ɋɨɜɦɟɫɬɧɨɟ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɬɚɛɥɢɰ ɪɚɡɧɵɯ ɬɢɩɨɜ ɦɨɠɟɬ ɛɵɬɶ ɬɚɤɠɟ ɨɫɧɨɜɚɧɨ ɧɚ ɬɨɦ ɩɪɢɧɰɢɩɟ, ɱɬɨɛɵ ɬɚɛɥɢɰɵ InnoDB ɢɫɩɨɥɶɡɨɜɚɥɢɫɶ ɜ ɜɟɞɭɳɟɣ ɛɚɡɟ ɞɚɧɧɵɯ, ɤɨɬɨɪɚɹ ɩɨɞɞɟɪɠɢɜɚɟɬ ɨɩɟɪɚɰɢɢ ɡɚɩɢɫɢ, ɚ ɜ ɜɟɞɨɦɵɯ ɛɚɡɚɯ ɞɚɧɧɵɯ ɩɨ-ɩɪɟɠɧɟɦɭ ɩɪɢɦɟɧɹɥɢɫɶ ɬɚɛɥɢɰɵ MyISAM, ɤɨɬɨɪɵɟ ɜ ɞɚɧɧɨɦ ɫɥɭɱɚɟ ɨɛɟɫɩɟɱɢɜɚɸɬ ɩɨɞɞɟɪɠɤɭ ɬɨɥɶɤɨ ɨɩɟɪɚɰɢɣ ɱɬɟɧɢɹ. ɋɥɟɞɭɟɬ ɬɳɚɬɟɥɶɧɨ ɩɪɨɞɭɦɚɬɶ ɜɨɩɪɨɫ ɨ ɬɨɦ, ɞɟɣɫɬɜɢɬɟɥɶɧɨ ɥɢ ɬɪɟɛɭɸɬɫɹ ɬɚɛɥɢɰɵ ɫ ɩɨɞɞɟɪɠɤɨɣ ɬɪɚɧɡɚɤɰɢɣ. ɉɪɢɦɟɧɟɧɢɟ ɷɬɢɯ ɬɚɛɥɢɰ ɫɜɹɡɚɧɨ ɫ ɜɨɡɧɢɤɧɨɜɟɧɢɟɦ ɡɧɚɱɢɬɟɥɶɧɵɯ ɞɨɩɨɥɧɢɬɟɥɶɧɵɯ ɢɡɞɟɪɠɟɤ ɢ ɩɨɷɬɨɦɭ ɩɪɢɜɨɞɢɬ ɤ ɡɚɦɟɞɥɟɧɢɸ; ɫɚɦɢ ɬɚɛɥɢɰɵ ɡɚɧɢɦɚɸɬ ɛɨɥɶɲɟ ɦɟɫɬɚ ɧɚ ɠɟɫɬɤɨɦ ɞɢɫɤɟ ɢ ɬɪɟɛɭɸɬ ɞɥɹ ɫɜɨɟɝɨ ɨɛɫɥɭɠɢɜɚɧɢɹ ɞɨɩɨɥɧɢɬɟɥɶɧɵɟ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɟ ɫɪɟɞɫɬɜɚ ɢ ɩɪɨɰɟɞɭɪɵ. ȿɫɥɢ ɢɫɩɨɥɶɡɭɸɬɫɹ ɬɚɛɥɢɰɵ ɫ ɩɨɞɞɟɪɠɤɨɣ ɬɪɚɧɡɚɤɰɢɣ, ɬɨ ɧɟɤɨɬɨɪɵɟ ɨɩɟɪɚɰɢɢ, ɬɚɤɢɟ ɤɚɤ ɜɨɫɫɬɚɧɨɜɥɟɧɢɟ ɛɚɡɵ ɞɚɧɧɵɯ ɩɨɫɥɟ ɫɛɨɹ, ɞɨɥɠɧɵ ɜɵɩɨɥɧɹɬɶɫɹ ɜɨ ɦɧɨɝɨɦ ɢɧɚɱɟ ɩɨ ɫɪɚɜɧɟɧɢɸ ɫ ɩɪɟɠɧɢɦɢ ɨɩɟɪɚɰɢɹɦɢ ɢ ɦɨɝɭɬ ɨɤɚɡɚɬɶɫɹ ɫɥɨɠɧɟɟ (ɧɟɫɦɨɬɪɹ ɧɚ ɬɨ, ɱɬɨ ɤ ɢɫɩɨɥɶɡɨɜɚɧɢɸ ɩɨɞɨɛɧɵɯ ɨɩɟɪɚɰɢɣ, ɜɟɪɨɹɬɧɨ, ɩɪɢɞɟɬɫɹ ɩɪɢɛɟɝɚɬɶ ɧɟɦɧɨɝɨ ɪɟɠɟ). ɋ ɞɪɭɝɨɣ ɫɬɨɪɨɧɵ, ɟɫɥɢ ɛɚɡɚ ɞɚɧɧɵɯ MySQL ɞɨɥɠɧɚ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶɫɹ ɧɚ ɩɪɟɞɩɪɢɹɬɢɢ ɜ ɬɚɤɢɯ ɭɫɥɨɜɢɹɯ, ɤɨɝɞɚ ɬɪɟɛɭɸɬɫɹ ɩɨɞɞɟɪɠɤɚ ɬɪɚɧɡɚɤɰɢɣ, ɜɵɩɨɥɧɟɧɢɟ ɛɥɨɤɢɪɨɜɤɢ ɧɚ ɭɪɨɜɧɟ ɫɬɪɨɤɢ, ɜɧɟɲɧɢɟ ɤɥɸɱɢ ɢ ɝɨɪɹɱɟɟ ɪɟɡɟɪɜɧɨɟ ɤɨɩɢɪɨɜɚɧɢɟ, ɬɨ ɧɟɨɛɯɨɞɢɦɨ ɢɡɭɱɢɬɶ ɜɨɡɦɨɠɧɨɫɬɢ ɩɪɢɦɟɧɟɧɢɹ ɬɚɛɥɢɰ InnoDB. Ɍɚɛɥɢɰɵ ɫ ɩɨɞɞɟɪɠɤɨɣ ɬɪɚɧɡɚɤɰɢɣ ɞɪɭɝɨɝɨ ɬɢɩɚ, BDB, ɨɫɧɨɜɚɧɵ ɧɚ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɦɚɲɢɧɵ ɯɪɚɧɟɧɢɹ BerkeleyDB, ɤɨɬɨɪɚɹ ɪɚɡɪɚɛɨɬɚɧɚ ɤɨɦɩɚɧɢɟɣ Sleepycat Software. Ɍɚɛɥɢɰɵ BDB ɧɟ ɩɨɞɞɟɪɠɢɜɚɸɬ ɧɟɤɨɬɨɪɵɟ ɢɡ ɞɨɩɨɥɧɢɬɟɥɶɧɵɯ ɫɪɟɞɫɬɜ ɬɚɛɥɢɰ InnoDB, ɬɚɤɢɯ ɤɚɤ ɜɧɟɲɧɢɟ ɤɥɸɱɢ ɢ ɛɥɨɤɢɪɨɜɤɚ ɧɚ ɭɪɨɜɧɟ ɫɬɪɨɤɢ, ɢ ɧɟ ɫɨɜɫɟɦ ɹɫɧɨ, ɤɚɤɚɹ ɤɨɦɩɚɧɢɹ ɞɨɥɠɧɚ ɩɪɟɞɨɫɬɚɜɥɹɬɶ ɩɨɞɞɟɪɠɤɭ ɩɨɞɨɛɧɨɣ ɢɧɫɬɚɥɥɹɰɢɢ. Ȼɟɡɭɫɥɨɜɧɨ, ɬɚɛɥɢɰɵ ɫ ɩɨɞɞɟɪɠɤɨɣ ɬɪɚɧɡɚɤɰɢɣ ɜɫɟ ɟɳɟ ɨɫɬɚɸɬɫɹ ɧɟ ɫɬɨɥɶ ɲɢɪɨɤɨ ɪɚɫɩɪɨɫɬɪɚɧɟɧɧɵɦɢ ɢ, ɩɨ ɦɧɟɧɢɸ ɚɜɬɨɪɨɜ, ɢɫɩɨɥɶɡɭɸɬɫɹ ɜ ɨɫɧɨɜɧɨɦ ɜ ɬɚɤɢɯ ɫɢɬɭɚɰɢɹɯ, ɤɨɝɞɚ ɭ ɤɨɦɩɚɧɢɢ, ɷɤɫɩɥɭɚɬɢɪɭɸɳɟɣ ɩɪɢɤɥɚɞɧɨɟ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ, ɢɦɟɟɬɫɹ ɞɨɫɬɚɬɨɱɧɨ ɪɟɫɭɪɫɨɜ, ɱɬɨɛɵ ɩɪɢɜɥɟɱɶ ɤ ɪɚɛɨɬɟ ɚɞɦɢɧɢɫɬɪɚɬɨɪɨɜ ɛɚɡɵ ɞɚɧɧɵɯ, ɫɩɟɰɢɚɥɢɡɢɪɭɸɳɢɯɫɹ ɜ ɷɬɨɣ ɨɛɥɚɫɬɢ, ɢ ɩɪɢɨɛɪɟɫɬɢ ɧɟɨɛɯɨɞɢɦɵɟ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɟ ɫɪɟɞɫɬɜɚ, ɩɨɷɬɨɦɭ ɨɫɧɨɜɧɚɹ ɱɚɫɬɶ ɞɚɧɧɨɣ ɝɥɚɜɵ ɩɨɫɜɹɳɟɧɚ ɨɩɢɫɚɧɢɸ ɬɚɛɥɢɰ MyISAM. Ⱦɨɩɨɥɧɢɬɟɥɶɧɭɸ ɢɧɮɨɪɦɚɰɢɸ ɨ ɬɚɛɥɢ- Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 349 ɰɚɯ InnoDB ɦɨɠɧɨ ɩɨɥɭɱɢɬɶ ɩɨ ɚɞɪɟɫɭ www.innodb.com ɢɥɢ www.mysql.com/doc/en/ InnoDB.html. Совет Ⱦɜɨɢɱɧɚɹ ɜɟɪɫɢɹ ɫɟɪɜɟɪɚ MySQL ɞɥɹ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɵ Windows ɮɨɪɦɢɪɭɟɬɫɹ ɫ ɩɨɞɞɟɪɠɤɨɣ ɬɚɛɥɢɰ ɬɢɩɚ InnoDB, ɪɚɡɪɟɲɟɧɧɨɣ ɩɨ ɭɦɨɥɱɚɧɢɸ. ɇɨ ɮɚɤɬɢɱɟɫɤɢ ɫɨɡɞɚɜɚɟɦɵɟ ɬɚɛɥɢɰɵ ɧɟ ɨɬɧɨɫɹɬɫɹ ɤ ɬɢɩɭ InnoDB, ɟɫɥɢ ɹɜɧɨ ɧɟ ɭɤɚɡɚɧɨ, ɱɬɨ ɞɨɥɠɧɵ ɛɵɬɶ ɫɨɡɞɚɧɵ ɬɚɛɥɢɰɵ ɷɬɨɝɨ ɬɢɩɚ. Çàãðóçêà ïðîãðàììíîãî îáåñïå÷åíèÿ MySQL ȼɫɟ ɡɚɝɪɭɠɚɟɦɵɟ ɮɚɣɥɵ, ɨɬɧɨɫɹɳɢɟɫɹ ɤ ɩɪɨɝɪɚɦɦɧɨɦɭ ɨɛɟɫɩɟɱɟɧɢɸ MySQL, ɧɚɯɨɞɹɬɫɹ ɩɨ ɚɞɪɟɫɭ www.mysql.com/downloads/index.html. ȼɵɛɟɪɢɬɟ ɧɟɨɛɯɨɞɢɦɵɣ ɧɨɦɟɪ ɜɟɪɫɢɢ, ɚ ɬɚɤɠɟ ɭɤɚɠɢɬɟ ɬɪɟɛɭɟɦɭɸ ɩɥɚɬɮɨɪɦɭ ɧɚɫɬɨɥɶɤɨ ɬɨɱɧɨ, ɧɚɫɤɨɥɶɤɨ ɷɬɨ ɜɨɡɦɨɠɧɨ. Ɉɞɧɨɣ ɢɡ ɨɫɨɛɟɧɧɨɫɬɟɣ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ MySQL, ɜ ɨɬɥɢɱɢɟ ɨɬ ɛɨɥɶɲɢɧɫɬɜɚ ɞɪɭɝɢɯ ɫɟɪɜɟɪɨɜ ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ, ɹɜɥɹɟɬɫɹ ɬɨ, ɱɬɨ ɤɨɦɩɚɧɢɹ, ɪɚɡɪɚɛɚɬɵɜɚɸɳɚɹ ɷɬɭ ɛɚɡɭ ɞɚɧɧɵɯ, ɩɪɟɞɩɨɱɢɬɚɟɬ ɩɨɞɞɟɪɠɢɜɚɬɶ ɢɧɫɬɚɥɥɹɰɢɸ ɧɚ ɨɫɧɨɜɟ ɞɜɨɢɱɧɨɝɨ, ɚ ɧɟ ɢɫɯɨɞɧɨɝɨ ɤɨɞɚ. Ȼɟɡɭɫɥɨɜɧɨ, ɦɨɝɭɬ ɜɨɡɧɢɤɚɬɶ ɬɚɤɢɟ ɫɢɬɭɚɰɢɢ, ɤɨɝɞɚ ɬɪɟɛɭɟɬɫɹ ɫɮɨɪɦɢɪɨɜɚɬɶ ɢɫɩɨɥɧɹɟɦɵɣ ɮɚɣɥ ɫɚɦɨɫɬɨɹɬɟɥɶɧɨ, ɧɨ, ɤɚɤ ɩɪɚɜɢɥɨ, ɷɬɨɝɨ ɫɥɟɞɭɟɬ ɢɡɛɟɝɚɬɶ ɩɪɢ ɥɸɛɨɣ ɜɨɡɦɨɠɧɨɫɬɢ. ȼ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɛɚɡɚ ɞɚɧɧɵɯ MySQL ɢɧɨɝɞɚ ɩɨɫɬɚɜɥɹɟɬɫɹ ɜ ɫɨɫɬɚɜɟ ɞɢɫɬɪɢɛɭɬɢɜɨɜ Linux ɢɥɢ ɞɪɭɝɢɯ ɩɚɤɟɬɨɜ, ɧɨ ɟɫɥɢ ɬɪɟɛɭɟɬɫɹ ɭɫɬɚɧɨɜɢɬɶ ɛɨɥɟɟ ɫɨɜɪɟɦɟɧɧɭɸ ɜɟɪɫɢɸ ɷɬɨɣ ɛɚɡɵ ɞɚɧɧɵɯ, ɬɨ ɥɭɱɲɟ ɞɟɢɧɫɬɚɥɥɢɪɨɜɚɬɶ ɫɭɳɟɫɬɜɭɸɳɭɸ ɜɟɪɫɢɸ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɯ ɫɪɟɞɫɬɜ, ɩɪɟɞɭɫɦɨɬɪɟɧɧɵɯ ɞɥɹ ɤɨɧɤɪɟɬɧɨɣ ɩɥɚɬɮɨɪɦɵ, ɚ ɡɚɬɟɦ ɢɧɫɬɚɥɥɢɪɨɜɚɬɶ ɧɨɜɭɸ ɜɟɪɫɢɸ. Èíñòàëëÿöèÿ MySQL â îïåðàöèîííîé ñèñòåìå Windows ȼ ɩɨɫɥɟɞɧɟɟ ɜɪɟɦɹ ɩɪɢɦɟɧɹɟɦɚɹ ɩɨ ɭɦɨɥɱɚɧɢɸ ɩɪɨɰɟɞɭɪɚ ɢɧɫɬɚɥɥɹɰɢɢ MySQL ɜ ɥɸɛɨɣ ɜɟɪɫɢɢ Windows ɫɬɚɥɚ ɟɳɟ ɩɪɨɳɟ, ɩɨɫɤɨɥɶɤɭ ɬɟɩɟɪɶ ɷɬɚ ɛɚɡɚ ɞɚɧɧɵɯ ɩɨɫɬɭɩɚɟɬ ɩɨɥɶɡɨɜɚɬɟɥɸ, ɚɤɤɭɪɚɬɧɨ ɭɩɚɤɨɜɚɧɧɚɹ ɜ ɨɞɢɧ ɩɚɤɟɬ ɜɦɟɫɬɟ ɫ ɩɪɨɝɪɚɦɦɨɣ ɢɧɫɬɚɥɥɹɰɢɢ. Ⱦɨɫɬɚɬɨɱɧɨ ɩɪɨɫɬɨ ɡɚɝɪɭɡɢɬɶ ɢɧɫɬɚɥɥɹɰɢɨɧɧɵɣ ɩɚɤɟɬ, ɪɚɡɚɪɯɢɜɢɪɨɜɚɬɶ ɟɝɨ ɜ ɥɸɛɨɦ ɭɞɨɛɧɨɦ ɤɚɬɚɥɨɝɟ, ɚ ɡɚɬɟɦ ɜɵɡɜɚɬɶ ɧɚ ɜɵɩɨɥɧɟɧɢɟ ɩɪɨɝɪɚɦɦɭ setup.exe. ɉɪɨɝɪɚɦɦɚ ɢɧɫɬɚɥɥɹɰɢɢ ɫɨɩɪɨɜɨɠɞɚɟɬ ɩɨɥɶɡɨɜɚɬɟɥɹ ɧɚ ɩɪɨɬɹɠɟɧɢɢ ɜɫɟɝɨ ɧɟɫɥɨɠɧɨɝɨ ɩɪɨɰɟɫɫɚ ɢ ɩɨ ɭɦɨɥɱɚɧɢɸ ɢɧɫɬɚɥɥɢɪɭɟɬ ɜɫɟ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ ɜ ɤɚɬɚɥɨɝɟ C:\mysql, ɜɵɛɨɪ ɤɨɬɨɪɨɝɨ ɞɥɹ ɷɬɨɣ ɰɟɥɢ, ɩɨ-ɜɢɞɢɦɨɦɭ, ɹɜɥɹɟɬɫɹ ɫɬɨɥɶ ɠɟ ɩɨɞɯɨɞɹɳɢɦ, ɤɚɤ ɢ ɜɵɛɨɪ ɥɸɛɨɝɨ ɞɪɭɝɨɝɨ ɤɚɬɚɥɨɝɚ. ɋɪɚɡɭ ɩɨɫɥɟ ɢɧɫɬɚɥɥɹɰɢɢ ɦɨɠɧɨ ɩɪɨɜɟɪɢɬɶ ɪɚɛɨɬɭ ɫɟɪɜɟɪɚ, ɡɚɩɭɫɬɢɜ ɟɝɨ ɢɡ ɩɪɢɝɥɚɲɟɧɢɹ ɤ ɜɜɨɞɭ ɤɨɦɚɧɞ. ɉɟɪɟɣɞɢɬɟ ɜ ɬɨɬ ɤɚɬɚɥɨɝ, ɝɞɟ ɧɚɯɨɞɢɬɫɹ ɢɫɩɨɥɧɹɟɦɵɣ ɮɚɣɥ ɫɟɪɜɟɪɚ, mysqld (ɷɬɢɦ ɤɚɬɚɥɨɝɨɦ, ɩɨ ɜɫɟɣ ɜɢɞɢɦɨɫɬɢ, ɛɭɞɟɬ C:\mysql\bin), ɢ ɜɜɟɞɢɬɟ ɤɨɦɚɧɞɭ mysqld --console ȿɫɥɢ ɢɧɫɬɚɥɥɹɰɢɹ ɛɵɥɚ ɜɵɩɨɥɧɟɧɚ ɭɫɩɟɲɧɨ, ɬɨ ɧɚ ɷɤɪɚɧɟ ɩɨɹɜɹɬɫɹ ɧɟɤɨɬɨɪɵɟ ɫɨɨɛɳɟɧɢɹ ɫ ɢɧɮɨɪɦɚɰɢɟɣ ɨ ɡɚɩɭɫɤɟ ɫɟɪɜɟɪɚ ɢ ɜɜɨɞɟ ɜ ɞɟɣɫɬɜɢɟ ɩɨɞɞɟɪɠɤɢ InnoDB. ȿɫɥɢ ɠɟ ɡɚɩɭɫɤ ɫɟɪɜɟɪɚ ɧɟ ɩɪɨɢɫɯɨɞɢɬ, ɬɨ, ɩɨ-ɜɢɞɢɦɨɦɭ, ɜɨɡɧɢɤɚɥɢ ɩɪɨɛɥɟɦɵ ɫ ɩɪɚɜɚɦɢ ɞɨɫɬɭɩɚ. ɍɛɟɞɢɬɟɫɶ ɜ ɬɨɦ, ɱɬɨ ɤɚɬɚɥɨɝ, ɜ ɤɨɬɨɪɨɦ ɧɚɯɨɞɹɬɫɹ ɞɚɧɧɵɟ, ɞɨɫɬɭɩɟɧ ɞɥɹ ɬɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ (ɫɤɨɪɟɟ ɜɫɟɝɨ, mysql), ɨɬ ɢɦɟɧɢ ɤɨɬɨɪɨɝɨ ɷɤɫɩɥɭɚɬɢɪɭɸɬɫɹ ɩɪɨɰɟɫɫɵ ɛɚɡɵ ɞɚɧɧɵɯ. Ȼɟɡɭɫɥɨɜɧɨ, ɤɨɦɩɚɧɢɹ MySQL AB ɩɪɟɞɭɫɦɨɬɪɟɥɚ ɧɨɜɭɸ ɢ ɭɞɨɛɧɭɸ ɩɪɨɝɪɚɦɦɭ ɢɧɫɬɚɥɥɹɰɢɢ, ɧɨ ɧɟ ɜɨɫɩɨɥɶɡɨɜɚɥɚɫɶ ɜɫɟɦɢ ɜɨɡɦɨɠɧɨɫɬɹɦɢ ɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɝɨ ɢɧɬɟɪɮɟɣɫɚ Windows. ɉɪɟɞɩɨɱɬɢɬɟɥɶɧɵɦ ɫɩɨɫɨɛɨɦ ɷɤɫɩɥɭɚɬɚɰɢɢ ɫɟɪɜɟɪɚ MySQL, ɤɥɢɟɧɬɫɤɢɯ ɩɪɨɝɪɚɦɦ ɢ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɯ ɫɪɟɞɫɬɜ ɜɫɟ ɟɳɟ ɹɜɥɹɟɬɫɹ ɜɵɩɨɥɧɟɧɢɟ ɤɨɦɚɧɞ ɢɡ ɩɪɢɝɥɚɲɟɧɢɹ ɤ ɜɜɨɞɭ ɤɨɦɚɧɞ. 350 ×àñòü II. PHP è MySQL ɉɪɨɝɪɚɦɦɚ MySQL ɧɟ ɜɜɨɞɢɬ ɫɚɦɚ ɫɟɛɹ ɜ ɦɟɧɸ ɡɚɩɭɫɤɚ Start, ɢ ɞɚɠɟ ɧɟ ɩɪɟɞɭɫɦɨɬɪɟɧ ɞɨɫɬɚɬɨɱɧɨ ɭɞɨɛɧɵɣ ɫɩɨɫɨɛ ɨɫɬɚɧɨɜɚ ɫɟɪɜɟɪɚ ɫ ɩɨɦɨɳɶɸ ɝɪɚɮɢɱɟɫɤɨɝɨ ɢɧɬɟɪɮɟɣɫɚ ɩɨɥɶɡɨɜɚɬɟɥɹ. Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɟɫɥɢ ɜɵ ɨɛɵɱɧɨ ɡɚɩɭɫɤɚɟɬɟ ɫɟɪɜɟɪ, ɞɜɚɠɞɵ ɳɟɥɤɧɭɜ ɧɚ ɢɫɩɨɥɧɹɟɦɨɦ ɮɚɣɥɟ mysqld, ɬɨ ɧɟ ɡɚɛɭɞɶɬɟ ɩɟɪɟɞ ɨɫɬɚɧɨɜɨɦ ɤɨɦɩɶɸɬɟɪɚ ɨɫɬɚɧɨɜɢɬɶ ɩɪɨɰɟɫɫ ɫɟɪɜɟɪɚ ɜɪɭɱɧɭɸ (ɫ ɩɨɦɨɳɶɸ ɩɪɨɝɪɚɦɦɵ mysqladmin, ɨɤɨɧ Task List, Task Manager ɢɥɢ ɞɪɭɝɢɯ ɫɩɟɰɢɚɥɢɡɢɪɨɜɚɧɧɵɯ ɫɪɟɞɫɬɜ Windows). ȿɳɟ ɨɞɧɚ ɞɨɜɨɥɶɧɨ ɫɬɪɚɧɧɚɹ ɨɫɨɛɟɧɧɨɫɬɶ, ɤɨɬɨɪɚɹ ɡɧɚɱɢɬɟɥɶɧɨ ɨɫɥɨɠɧɹɟɬ ɪɚɛɨɬɭ ɩɨɥɶɡɨɜɚɬɟɥɟɣ Windows, ɜ ɨɬɥɢɱɢɟ ɨɬ ɩɨɥɶɡɨɜɚɬɟɥɟɣ Unix, ɫɨɫɬɨɢɬ ɜ ɬɨɦ, ɱɬɨ ɜ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɫɩɪɚɜɨɱɧɨɟ ɪɭɤɨɜɨɞɫɬɜɨ ɩɨ ɹɡɵɤɭ MySQL ɩɨɫɬɭɩɚɟɬ ɤ ɩɨɥɶɡɨɜɚɬɟɥɹɦ Windows ɜ ɜɢɞɟ ɨɞɧɨɝɨ ɨɝɪɨɦɧɨɝɨ ɮɚɣɥɚ HTML ɢɥɢ ɬɟɤɫɬɨɜɨɝɨ ɮɚɣɥɚ. ɗɬɨ ɪɭɤɨɜɨɞɫɬɜɨ ɜɯɨɞɢɬ ɜ ɫɨɫɬɚɜ ɞɢɫɬɪɢɛɭɬɢɜɚ ɞɥɹ Windows, ɚ ɬɚɤɠɟ ɩɪɟɞɨɫɬɚɜɥɹɟɬɫɹ ɨɬɞɟɥɶɧɨ ɜ ɜɢɞɟ ɚɪɯɢɜɧɨɝɨ ɮɚɣɥɚ. ɗɬɨɬ ɮɚɣɥ ɧɚɫɬɨɥɶɤɨ ɜɟɥɢɤ, ɱɬɨ ɫ ɧɢɦ ɧɟɜɨɡɦɨɠɧɨ ɞɚɠɟ ɭɫɩɟɲɧɨ ɪɚɛɨɬɚɬɶ, ɟɫɥɢ ɤɨɦɩɶɸɬɟɪ Windows — ɧɟ ɨɱɟɧɶ ɦɨɳɧɵɣ ɢ ɛɵɫɬɪɨɞɟɣɫɬɜɭɸɳɢɣ. ɉɨ ɜɨɡɦɨɠɧɨɫɬɢ ɜɦɟɫɬɨ ɧɟɝɨ ɡɚɝɪɭɡɢɬɟ ɫ Web-ɭɡɥɚ MySQL ɭɩɚɤɨɜɚɧɧɭɸ ɜɟɪɫɢɸ ɜ ɜɢɞɟ ɮɚɣɥɚ ɮɨɪɦɚɬɚ tar (tar-ɮɚɣɥɚ), ɜ ɤɨɬɨɪɨɣ ɞɥɹ ɤɚɠɞɨɣ ɝɥɚɜɵ ɪɭɤɨɜɨɞɫɬɜɚ ɩɪɟɞɭɫɦɨɬɪɟɧ ɨɬɞɟɥɶɧɵɣ ɮɚɣɥ HTML. ɗɬɢ ɮɚɣɥɵ ɦɨɠɧɨ ɢɡɜɥɟɱɶ ɧɚ ɤɨɦɩɶɸɬɟɪɟ Unix, ɚ ɡɚɬɟɦ ɫɤɨɩɢɪɨɜɚɬɶ ɧɚ ɤɨɦɩɶɸɬɟɪ Windows. ȿɳɟ ɨɞɢɧ ɜɚɪɢɚɧɬ ɫɨɫɬɨɢɬ ɜ ɬɨɦ, ɱɬɨ ɜɫɟɝɞɚ ɜɨɡɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɞɨɤɭɦɟɧɬɚɰɢɸ, ɩɪɟɞɨɫɬɚɜɥɟɧɧɭɸ ɞɥɹ ɞɨɫɬɭɩɚ ɜ ɨɩɟɪɚɬɢɜɧɨɦ ɪɟɠɢɦɟ, ɟɫɥɢ ɭ ɜɚɫ ɟɫɬɶ ɧɚɞɟɠɧɵɣ ɞɨɫɬɭɩ ɤ ɂɧɬɟɪɧɟɬ. ȼɟɪɫɢɹ PHP ɞɥɹ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɵ Windows ɩɨɫɬɭɩɚɟɬ ɫ ɩɨɞɞɟɪɠɤɨɣ MySQL, ɪɚɡɪɟɲɟɧɧɨɣ ɩɨ ɭɦɨɥɱɚɧɢɸ, ɩɨɷɬɨɦɭ ɩɨɫɥɟ ɢɧɫɬɚɥɥɹɰɢɢ ɷɬɨɣ ɛɚɡɵ ɞɚɧɧɵɯ ɦɨɠɧɨ ɫɪɚɡɭ ɠɟ ɩɪɢɫɬɭɩɚɬɶ ɤ ɪɚɛɨɬɟ (ɪɚɡɭɦɟɟɬɫɹ, ɩɨɫɥɟ ɜɵɩɨɥɧɟɧɢɹ ɜɫɟɯ ɧɟɨɛɯɨɞɢɦɵɯ ɨɩɟɪɚɰɢɣ ɭɩɪɚɜɥɟɧɢɹ ɩɨɥɶɡɨɜɚɬɟɥɹɦɢ, ɤɨɬɨɪɵɟ ɪɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɜ ɨɞɧɨɦ ɢɡ ɩɨɫɥɟɞɧɢɯ ɪɚɡɞɟɥɨɜ ɷɬɨɣ ɝɥɚɜɵ). ȿɫɥɢ ɬɪɟɛɭɟɬɫɹ ɨɬɤɥɸɱɢɬɶ ɩɨɞɞɟɪɠɤɭ ɪɚɫɲɢɪɟɧɢɹ mysql ɜ ɩɨɥɶɡɭ ɪɚɫɲɢɪɟɧɢɹ mysqli, ɬɨ ɧɟɨɛɯɨɞɢɦɨ ɡɚɤɨɦɦɟɧɬɢɪɨɜɚɬɶ ɫɬɪɨɤɭ mysql ɢ ɪɚɫɤɨɦɦɟɧɬɢɪɨɜɚɬɶ ɫɬɪɨɤɭ mysqli ɜ ɪɚɡɞɟɥɟ modules ɮɚɣɥɚ php.ini. Èíñòàëëÿöèÿ MySQL â îïåðàöèîííîé ñèñòåìå Unix ɉɨ ɜɨɡɦɨɠɧɨɫɬɢ ɢɫɩɨɥɶɡɭɣɬɟ ɨɞɧɭ ɢɡ ɞɜɨɢɱɧɵɯ ɜɟɪɫɢɣ MySQL, ɩɪɢɱɟɦ ɥɭɱɲɟ ɜɫɟɝɨ ɬɭ ɢɡ ɧɢɯ, ɞɥɹ ɤɨɬɨɪɨɣ ɩɪɟɞɭɫɦɨɬɪɟɧɚ ɩɪɨɝɪɚɦɦɚ ɢɧɫɬɚɥɥɹɰɢɢ. ɇɚ ɧɟɤɨɬɨɪɵɯ ɩɥɚɬɮɨɪɦɚɯ (ɨɫɨɛɟɧɧɨ ɧɚ ɩɥɚɬɮɨɪɦɟ Linux) ɩɪɢɯɨɞɢɬɫɹ ɡɚɝɪɭɠɚɬɶ ɫɟɪɜɟɪɧɨɟ ɢ ɤɥɢɟɧɬɫɤɨɟ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ ɨɬɞɟɥɶɧɨ, ɚ ɧɚ ɞɪɭɝɢɯ ɩɥɚɬɮɨɪɦɚɯ ɩɪɟɞɭɫɦɨɬɪɟɧɵ ɭɞɨɛɧɵɟ ɢɧɫɬɚɥɥɹɰɢɨɧɧɵɟ ɩɚɤɟɬɵ, ɫɨɞɟɪɠɚɳɢɟ ɜɫɟ ɧɟɨɛɯɨɞɢɦɨɟ. ȼ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɢɦɟɟɬɫɹ ɛɨɝɚɬɵɣ ɜɵɛɨɪ ɞɜɨɢɱɧɵɯ ɢɧɫɬɚɥɥɹɰɢɨɧɧɵɯ ɩɚɤɟɬɨɜ, ɩɨɷɬɨɦɭ ɞɥɹ ɛɨɥɶɲɢɧɫɬɜɚ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɧɟ ɜɨɡɧɢɤɚɟɬ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɫɨɛɢɪɚɬɶ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ MySQL ɜɪɭɱɧɭɸ. ɇɟɤɨɬɨɪɵɟ ɩɚɤɟɬɵ ɪɚɫɩɪɨɫɬɪɚɧɹɸɬɫɹ ɫɬɨɪɨɧɧɢɦɢ ɪɚɡɪɚɛɨɬɱɢɤɚɦɢ, ɬɚɤɢɦɢ ɤɚɤ ɤɨɦɩɚɧɢɹ Debian, ɚ ɧɟ ɤɨɦɩɚɧɢɟɣ MySQL AB. ȿɫɥɢ ɧɟ ɫɦɨɠɟɬɟ ɧɚɣɬɢ ɧɭɠɧɭɸ ɞɜɨɢɱɧɭɸ ɜɟɪɫɢɸ ɧɚ ɭɡɥɟ mysql.com, ɩɪɨɜɟɞɢɬɟ ɩɨɢɫɤ ɜ ɬɨɦ ɢɫɬɨɱɧɢɤɟ ɞɜɨɢɱɧɵɯ ɩɚɤɟɬɨɜ (ɫɩɟɰɢɚɥɶɧɨ ɩɪɟɞɧɚɡɧɚɱɟɧɧɵɯ ɞɥɹ ɜɚɲɟɣ ɩɥɚɬɮɨɪɦɵ), ɤɨɬɨɪɵɣ ɜɵ ɨɛɵɱɧɨ ɢɫɩɨɥɶɡɭɟɬɟ. Ɍɨɱɧɨɟ ɦɟɫɬɨ ɪɚɡɦɟɳɟɧɢɹ ɩɪɨɝɪɚɦɦ ɢ ɮɚɣɥɨɜ ɞɚɧɧɵɯ MySQL ɢɡɦɟɧɹɟɬɫɹ ɜ ɨɱɟɧɶ ɲɢɪɨɤɢɯ ɩɪɟɞɟɥɚɯ, ɜ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɬɨɝɨ, ɤɚɤɨɣ ɩɚɤɟɬ ɢɫɩɨɥɶɡɭɟɬɫɹ ɢ ɢɡ ɤɚɤɨɝɨ ɢɫɬɨɱɧɢɤɚ ɨɧ ɩɨɥɭɱɟɧ. ȼ ɪɭɤɨɜɨɞɫɬɜɟ, ɤɨɬɨɪɨɟ ɧɚɯɨɞɢɬɫɹ ɧɚ ɭɡɥɟ mysql.com, ɩɪɟɞɭɫɦɨɬɪɟɧ ɨɬɞɟɥɶɧɵɣ ɪɚɡɞɟɥ ɫ ɨɩɢɫɚɧɢɟɦ ɢɧɫɬɚɥɥɹɰɢɨɧɧɵɯ ɤɨɦɩɨɧɨɜɨɤ, ɧɨ ɫɨɞɟɪɠɚɳɢɟɫɹ ɜ ɧɟɦ ɞɚɧɧɵɟ ɩɪɢɦɟɧɢɬɟɥɶɧɨ ɤ ɧɟɤɨɬɨɪɵɦ ɩɥɚɬɮɨɪɦɚɦ ɱɚɫɬɨ ɛɵɜɚɸɬ ɧɟɩɪɢɦɟɧɢɦɵɦɢ ɢɥɢ ɧɟɬɨɱɧɵɦɢ. ɇɚɢɛɨɥɟɟ ɱɚɫɬɨ ɢɫɩɨɥɶɡɭɟɦɵɦɢ ɤɚɬɚɥɨɝɚɦɢ ɹɜɥɹɸɬɫɹ /usr, /usr/local ɢ /var. ȿɫɥɢ ɩɪɢɯɨɞɢɬɫɹ ɩɪɢɦɟɧɹɬɶ ɭɧɢɜɟɪɫɚɥɶɧɵɣ ɞɜɨɢɱɧɵɣ ɢɧɫɬɚɥɥɹɰɢɨɧɧɵɣ ɩɚɤɟɬ ɜɦɟɫɬɨ ɭɞɨɛɧɨɣ ɜɟɪɫɢɢ, ɜ ɤɨɬɨɪɨɣ ɩɪɟɞɭɫɦɨɬɪɟɧɚ ɢɧɫɬɚɥɥɹɰɢɨɧɧɚɹ ɩɪɨɝɪɚɦɦɚ, ɬɨ ɞɥɹ ɭɫɬɚɧɨɜɤɢ ɛɚɡɵ ɞɚɧɧɵɯ MySQL ɦɨɠɟɬ ɩɨɬɪɟɛɨɜɚɬɶɫɹ ɜɵɩɨɥɧɢɬɶ ɧɟɫɤɨɥɶɤɢɯ ɞɨɩɨɥɧɢɬɟɥɶɧɵɯ ɷɬɚɩɨɜ. ȼɜɟɞɢɬɟ ɫɥɟɞɭɸɳɢɟ ɫɬɪɨɤɢ ɜ ɩɪɢɝɥɚɲɟɧɢɢ ɤ ɜɜɨɞɭ ɤɨɦɚɧɞ, ɱɬɨɛɵ ɫɨɡɞɚɬɶ ɧɨɜɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ mysql ɢ ɢɧɫɬɚɥɥɢɪɨɜɚɬɶ MySQL ɞɥɹ ɷɤɫɩɥɭɚɬɚɰɢɢ ɨɬ ɢɦɟɧɢ ɞɚɧɧɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ (ɞɥɹ ɷɬɨɝɨ ɧɟɨɛɯɨɞɢɦɨ ɜɧɚɱɚɥɟ ɩɟɪɟɣɬɢ ɜ ɭɱɟɬɧɭɸ ɡɚɩɢɫɶ root): Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 351 groupadd mysql useradd -g mysql mysql cd /usr/local gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf ln -s full-path-to-mysql-VERSION-OS mysql cd mysql scripts/mysql_install_db chown -R root . chown -R mysql data chgrp -R mysql . bin/mysqld_safe --user=mysql & ɉɨɥɶɡɨɜɚɬɟɥɢ ɜɟɪɫɢɢ MySQL 3.x ɞɨɥɠɧɵ ɭɱɢɬɵɜɚɬɶ, ɱɬɨ ɧɨɜɵɣ ɫɰɟɧɚɪɢɣ ɡɚɩɭɫɤɚ ɞɥɹ MySQL ɬɟɩɟɪɶ ɧɚɡɵɜɚɟɬɫɹ mysqld_safe, ɚ ɧɟ safe_mysqld. Ɍɟɦ ɧɟ ɦɟɧɟɟ ɩɨɫɥɟɞɧɟɟ ɢɦɹ ɜɫɟ ɟɳɟ ɛɭɞɟɬ ɫɨɯɪɚɧɹɬɶɫɹ ɤɚɤ ɫɢɦɜɨɥɢɱɟɫɤɚɹ ɫɫɵɥɤɚ ɧɚ ɩɪɨɬɹɠɟɧɢɢ ɨɩɪɟɞɟɥɟɧɧɨɝɨ ɩɟɪɟɯɨɞɧɨɝɨ ɩɟɪɢɨɞɚ ɞɥɹ ɨɛɪɚɬɧɨɣ ɫɨɜɦɟɫɬɢɦɨɫɬɢ. Ɍɟɩɟɪɶ ɜɫɟ ɝɨɬɨɜɨ ɞɥɹ ɫɨɡɞɚɧɢɹ ɢɫɩɨɥɧɹɟɦɨɝɨ ɮɚɣɥɚ PHP ɫ ɤɥɢɟɧɬɫɤɢɦɢ ɛɢɛɥɢɨɬɟɤɚɦɢ MySQL. ɂɫɩɨɥɶɡɭɣɬɟ ɨɩɰɢɸ --with-mysql=/path/to/mysql ɞɥɹ ɛɨɥɟɟ ɫɬɚɪɵɯ ɜɟɪɫɢɣ MySQL ɢɥɢ ɨɩɰɢɢ --without-mysql --with-mysqli=/path/to/mysql_config ɞɥɹ MySQL 4.1 ɢ ɩɨɫɥɟɞɭɸɳɢɯ ɜɟɪɫɢɣ. Ɉɛɪɚɬɢɬɟ ɜɧɢɦɚɧɢɟ ɧɚ ɬɨ, ɱɬɨ ɜ ɜɟɪɫɢɢ MySQL 4 ɧɟɨɛɯɨɞɢɦɨ ɡɚɞɚɜɚɬɶ ɫɫɵɥɤɭ ɧɚ ɮɚɤɬɢɱɟɫɤɨɟ ɦɟɫɬɨɧɚɯɨɠɞɟɧɢɟ ɮɚɣɥɚ mysql_config, ɚ ɧɟ ɩɪɨɫɬɨ ɧɚ ɤɚɬɚɥɨɝ MySQL. ɋɰɟɧɚɪɢɣ mysql_config — ɷɬɨ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɟ ɫɪɟɞɫɬɜɨ, ɩɨɡɜɨɥɹɸɳɟɟ ɩɪɟɞɨɫɬɚɜɢɬɶ ɫɢɫɬɟɦɟ ɢɧɮɨɪɦɚɰɢɸ ɨɛ ɭɫɥɨɜɢɹɯ ɤɨɦɩɢɥɹɰɢɢ ɤɥɢɟɧɬɨɜ MySQL, ɜ ɱɚɫɬɧɨɫɬɢ, ɨ ɦɟɫɬɨɧɚɯɨɠɞɟɧɢɢ ɛɢɛɥɢɨɬɟɤ. Èíñòàëëÿöèÿ MySQL â îïåðàöèîííîé ñèñòåìå Mac OS X ȼ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɤɨɦɩɚɧɢɹ MySQL AB ɩɪɟɞɨɫɬɚɜɥɹɟɬ ɞɢɫɬɪɢɛɭɬɢɜ ɫ ɩɪɨɝɪɚɦɦɨɣ ɢɧɫɬɚɥɥɹɰɢɢ ɞɜɨɢɱɧɨɝɨ ɢɫɩɨɥɧɹɟɦɨɝɨ ɮɚɣɥɚ, ɫɩɟɰɢɚɥɶɧɨ ɩɪɟɞɧɚɡɧɚɱɟɧɧɨɣ ɞɥɹ OS X. ȼ ɫɨɫɬɚɜ ɷɬɨɝɨ ɞɢɫɬɪɢɛɭɬɢɜɚ ɜɯɨɞɢɬ ɨɛɪɚɡ ɞɢɫɤɚ, ɚ ɧɟ ɮɚɣɥ ɮɨɪɦɚɬɚ tar. ɉɪɨɫɬɨ ɡɚɝɪɭɡɢɬɟ ɮɚɣɥ ɫ ɪɚɫɲɢɪɟɧɢɟɦ .dmg ɢ ɞɜɚɠɞɵ ɳɟɥɤɧɢɬɟ ɧɚ ɩɨɹɜɢɜɲɟɣɫɹ ɩɢɤɬɨɝɪɚɦɦɟ. ɉɪɨɝɪɚɦɦɚ ɢɧɫɬɚɥɥɹɰɢɢ ɫɨɩɪɨɜɨɠɞɚɟɬ ɩɨɥɶɡɨɜɚɬɟɥɹ ɧɚ ɩɪɨɬɹɠɟɧɢɢ ɜɫɟɝɨ ɩɪɨɰɟɫɫɚ ɢ ɩɪɟɞɥɚɝɚɟɬ ɡɚɞɚɧɧɵɣ ɩɨ ɭɦɨɥɱɚɧɢɸ ɩɭɬɶ ɢɧɫɬɚɥɥɹɰɢɢ. ɉɨɥɶɡɨɜɚɬɟɥɢ ɩɪɨɝɪɚɦɦɵ Mac Internet Explorer ɦɨɝɭɬ ɨɛɧɚɪɭɠɢɬɶ, ɱɬɨ ɮɚɣɥ MySQL ɡɚɝɪɭɠɚɟɬɫɹ ɩɨɞ ɢɦɟɧɟɦ download.php, ɚ ɧɟ mysql-standard-4.x.x.dmg. ȼ ɬɚɤɨɦ ɫɥɭɱɚɟ ɞɨɠɞɢɬɟɫɶ ɡɚɜɟɪɲɟɧɢɹ ɡɚɝɪɭɡɤɢ, ɚ ɡɚɬɟɦ ɢɡɦɟɧɢɬɟ ɢɦɹ ɮɚɣɥɚ. Âñïîìîãàòåëüíûå ðàáîòû, âûïîëíÿåìûå ïîñëå èíñòàëëÿöèè ɉɨɫɬɚɜɤɚ MySQL ɜɵɩɨɥɧɹɟɬɫɹ ɫ ɩɭɫɬɵɦ ɩɚɪɨɥɟɦ ɞɥɹ ɩɨɥɶɡɨɜɚɬɟɥɹ root ɛɚɡɵ ɞɚɧɧɵɯ MySQL. Ʉɚɤ ɬɨɥɶɤɨ ɛɭɞɟɬ ɡɚɜɟɪɲɟɧɚ ɭɫɩɟɲɧɚɹ ɢɧɫɬɚɥɥɹɰɢɹ ɛɚɡɵ ɞɚɧɧɵɯ ɢ ɤɥɢɟɧɬɨɜ (ɢ ɩɨ ɜɨɡɦɨɠɧɨɫɬɢ ɟɳɟ ɞɨ ɬɨɝɨ, ɤɚɤ ɛɭɞɟɬ ɫɨɡɞɚɧ ɢɫɩɨɥɧɹɟɦɵɣ ɮɚɣɥ PHP ɫ ɩɨɞɞɟɪɠɤɨɣ MySQL), ɧɟɨɛɯɨɞɢɦɨ ɡɚɞɚɬɶ ɩɚɪɨɥɶ ɩɨɥɶɡɨɜɚɬɟɥɹ root ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: mysqladmin -u root password 'new_password'; Ɉɱɟɜɢɞɧɨ, ɱɬɨ ɩɪɢ ɷɬɨɦ ɜɦɟɫɬɨ ɩɪɢɜɟɞɟɧɧɨɝɨ ɜɵɲɟ ɨɛɨɡɧɚɱɟɧɢɹ new_password ɧɟɨɛɯɨɞɢɦɨ ɡɚɞɚɬɶ ɞɟɣɫɬɜɢɬɟɥɶɧɵɣ ɩɚɪɨɥɶ. 352 ×àñòü II. PHP è MySQL Внимание! ɇɢ ɩɪɢ ɤɚɤɢɯ ɨɛɫɬɨɹɬɟɥɶɫɬɜɚɯ ɧɟ ɫɥɟɞɭɟɬ ɞɨɩɭɫɤɚɬɶ ɞɚɠɟ ɦɵɫɥɢ ɨ ɬɨɦ, ɱɬɨɛɵ ɜ ɩɪɢɜɟɞɟɧɧɨɣ ɜɵɲɟ ɤɨɦɚɧɞɟ ɜ ɤɚɱɟɫɬɜɟ ɩɚɪɨɥɹ ɩɨɥɶɡɨɜɚɬɟɥɹ root ɩɪɢɦɟɧɹɥɫɹ ɩɚɪɨɥɶ ɩɨɥɶɡɨɜɚɬɟɥɹ root ɫɟɪɜɟɪɧɨɝɨ ɤɨɦɩɶɸɬɟɪɚ! ɉɨɥɶɡɨɜɚɬɟɥɶ root ɫɟɪɜɟɪɚ ɢ ɩɨɥɶɡɨɜɚɬɟɥɶ root ɛɚɡɵ ɞɚɧɧɵɯ ɧɟ ɢɦɟɸɬ ɧɢɤɚɤɨɝɨ ɨɬɧɨɲɟɧɢɹ ɞɪɭɝ ɤ ɞɪɭɝɭ. Ʉɪɨɦɟ ɬɨɝɨ, ɜ ɤɚɱɟɫɬɜɟ ɩɚɪɨɥɹ ɩɨɥɶɡɨɜɚɬɟɥɹ root ɛɚɡɵ ɞɚɧɧɵɯ ɧɟ ɫɥɟɞɭɟɬ ɩɪɢɦɟɧɹɬɶ ɫɜɨɣ ɨɛɵɱɧɵɣ ɩɚɪɨɥɶ ɩɨɥɶɡɨɜɚɬɟɥɹ. ɇɚɫɬɨɹɬɟɥɶɧɨ ɪɟɤɨɦɟɧɞɭɟɦ ɧɟ ɷɤɨɧɨɦɢɬɶ ɭɫɢɥɢɹ ɢ ɩɨɞɝɨɬɨɜɢɬɶ ɧɟ ɢɫɩɨɥɶɡɨɜɚɜɲɢɣɫɹ ɪɚɧɟɟ ɩɚɪɨɥɶ. ɉɨɥɶɡɨɜɚɬɟɥɹɦ Unix ɦɨɠɟɬ ɬɚɤɠɟ ɩɨɬɪɟɛɨɜɚɬɶɫɹ ɜɜɟɫɬɢ ɢɦɹ ɤɚɬɚɥɨɝɚ MySQL ɜ ɫɨɫɬɚɜ ɩɟɪɟɦɟɧɧɨɣ PATH, ɱɬɨɛɵ ɧɟ ɧɭɠɧɨ ɛɵɥɨ ɤɚɠɞɵɣ ɪɚɡ ɜɜɨɞɢɬɶ ɩɨɥɧɨɟ ɢɦɹ ɩɭɬɢ ɞɥɹ ɜɵɡɨɜɚ ɧɚ ɜɵɩɨɥɧɟɧɢɟ ɤɥɢɟɧɬɫɤɨɣ ɩɪɨɝɪɚɦɦɵ ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ. ɉɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ bash ɫɨɨɬɜɟɬɫɬɜɭɸɳɚɹ ɤɨɦɚɧɞɚ ɛɭɞɟɬ ɜɵɝɥɹɞɟɬɶ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: export PATH=$PATH:/usr/local/mysql Ɉɬɤɨɪɪɟɤɬɢɪɭɣɬɟ ɷɬɭ ɤɨɦɚɧɞɭ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɬɪɟɛɨɜɚɧɢɹɦɢ ɩɪɢɦɟɧɹɟɦɨɝɨ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ. ȿɫɥɢ ɡɚɩɢɫɶ ɫ ɭɤɚɡɚɧɢɟɦ ɞɚɧɧɨɝɨ ɤɚɬɚɥɨɝɚ ɛɭɞɟɬ ɞɨɛɚɜɥɟɧɚ ɜ ɫɬɪɨɤɭ PATH ɮɚɣɥɚ ɡɚɩɭɫɤɚ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ (ɧɚɩɪɢɦɟɪ, .bashrc), ɬɨ ɧɟ ɩɪɢɞɟɬɫɹ ɜɵɩɨɥɧɹɬɶ ɷɬɨɬ ɲɚɝ ɩɨɫɥɟ ɤɚɠɞɨɣ ɪɟɝɢɫɬɪɚɰɢɢ ɧɚ ɤɨɦɩɶɸɬɟɪɟ. Ɍɟɩɟɪɶ ɫɟɪɜɟɪ MySQL ɝɨɬɨɜ ɤ ɷɤɫɩɥɭɚɬɚɰɢɢ. Îñíîâíûå êëèåíòñêèå êîìàíäû MySQL ɇɚ ɩɟɪɜɵɯ ɩɨɪɚɯ ɭ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɜɵɡɵɜɚɟɬ ɭɞɢɜɥɟɧɢɟ ɢɧɮɨɪɦɚɰɢɹ ɨ ɬɨɦ, ɱɬɨ ɞɜɨɢɱɧɵɣ ɮɚɣɥ mysql, ɧɚɯɨɞɹɳɢɣɫɹ ɜ ɤɚɬɚɥɨɝɟ mysql/bin, ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɧɟ ɫɟɪɜɟɪɧɭɸ, ɚ ɤɥɢɟɧɬɫɤɭɸ ɩɪɨɝɪɚɦɦɭ (ɫɟɪɜɟɪɧɚɹ ɩɪɨɝɪɚɦɦɚ ɢɦɟɟɬ ɢɦɹ mysqld). ɉɨɫɥɟ ɜɜɨɞɚ ɢɦɟɧɢ mysql ɜ ɩɪɢɝɥɚɲɟɧɢɢ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ ɩɪɨɢɫɯɨɞɢɬ ɜɵɡɨɜ ɤɥɢɟɧɬɫɤɨɣ ɩɪɨɝɪɚɦɦɵ MySQL ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ, ɩɨɡɜɨɥɹɸɳɟɣ ɩɨɥɭɱɢɬɶ ɞɨɫɬɭɩ ɤ ɨɞɧɨɦɭ ɢɡ ɫɟɪɜɟɪɨɜ MySQL. ɑɬɨɛɵ ɩɨɞɤɥɸɱɢɬɶɫɹ ɤ ɫɟɪɜɟɪɭ MySQL ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɤɥɢɟɧɬɚ ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ, ɧɟɨɛɯɨɞɢɦɨ ɜɜɟɫɬɢ ɫɥɟɞɭɸɳɭɸ ɩɪɨɫɬɭɸ ɤɨɦɚɧɞɭ: mysql [-h hostname] [-P portnumber] -u username -p ɉɪɢ ɷɬɨɦ ɩɨɱɬɢ ɧɚɜɟɪɧɹɤɚ ɩɨɬɪɟɛɭɟɬɫɹ ɭɤɚɡɚɬɶ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ username, ɬɚɤ ɤɚɤ ɜ ɩɪɨɬɢɜɧɨɦ ɫɥɭɱɚɟ ɤɥɢɟɧɬɫɤɚɹ ɩɪɨɝɪɚɦɦɚ ɛɭɞɟɬ ɩɵɬɚɬɶɫɹ ɢɫɩɨɥɶɡɨɜɚɬɶ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ. ȿɫɥɢ ɧɟ ɛɭɞɟɬ ɭɤɚɡɚɧɚ ɨɩɰɢɹ ɩɚɪɨɥɹ -p, ɬɨ ɩɪɨɝɪɚɦɦɚ mysql ɩɪɨɜɟɪɢɬ, ɬɪɟɛɭɟɬɫɹ ɥɢ ɩɚɪɨɥɶ ɞɥɹ ɬɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ, ɤɨɬɨɪɵɣ ɩɵɬɚɟɬɫɹ ɩɨɞɤɥɸɱɢɬɶɫɹ ɤ ɫɟɪɜɟɪɭ, ɢ ɟɫɥɢ ɩɚɪɨɥɶ ɞɟɣɫɬɜɢɬɟɥɶɧɨ ɬɪɟɛɭɟɬɫɹ, ɧɨ ɧɟ ɡɚɞɚɧ, ɨɬɜɟɪɝɧɟɬ ɩɨɩɵɬɤɭ ɩɨɞɤɥɸɱɟɧɢɹ. ȿɫɥɢ ɩɪɨɢɫɯɨɞɢɬ ɩɨɞɤɥɸɱɟɧɢɟ ɤ ɥɨɤɚɥɶɧɨɦɭ ɯɨɫɬɭ, ɬɨ ɨɩɰɢɸ -h ɫ ɢɦɟɧɟɦ ɯɨɫɬɚ hostname ɡɚɞɚɜɚɬɶ ɧɟ ɬɪɟɛɭɟɬɫɹ, ɚ ɟɫɥɢ ɩɨɞɤɥɸɱɟɧɢɟ ɩɪɨɢɫɯɨɞɢɬ ɤ ɩɪɢɦɟɧɹɟɦɨɦɭ ɩɨ ɭɦɨɥɱɚɧɢɸ ɩɨɪɬɭ (3306), ɧɟ ɧɭɠɧɨ ɡɚɞɚɜɚɬɶ ɨɩɰɢɸ -P ɫ ɧɨɦɟɪɨɦ ɩɨɪɬɚ portnumber. Ⱦɥɹ ɤɨɦɚɧɞɵ MySQL ɩɪɟɞɭɫɦɨɬɪɟɧ ɰɟɥɵɣ ɪɹɞ ɞɪɭɝɢɯ ɨɩɰɢɣ, ɧɨ ɨɛɵɱɧɨ ɧɚ ɩɟɪɜɵɯ ɩɨɪɚɯ ɞɨɫɬɚɬɨɱɧɨ ɩɪɢɦɟɧɢɬɶ ɨɩɢɫɚɧɧɵɟ ɡɞɟɫɶ ɨɩɰɢɢ. ɉɪɟɞɩɨɥɨɠɢɦ, ɱɬɨ ɩɪɢ ɩɨɞɤɥɸɱɟɧɢɢ ɭɤɚɡɚɧɨ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ root; ɜ ɬɚɤɨɦ ɫɥɭɱɚɟ ɛɭɞɟɬ ɜɵɜɟɞɟɧɨ ɩɪɢɝɥɚɲɟɧɢɟ ɤ ɜɜɨɞɭ ɩɚɪɨɥɹ ɩɨɥɶɡɨɜɚɬɟɥɹ root, ɤɨɬɨɪɵɣ ɛɵɥ ɡɚɞɚɧ ɧɚ ɩɪɟɞɵɞɭɳɟɦ ɷɬɚɩɟ. ɉɨɫɥɟ ɩɨɞɤɥɸɱɟɧɢɹ ɤ ɫɟɪɜɟɪɭ ɧɟɨɛɯɨɞɢɦɨ ɜɵɛɪɚɬɶ ɢɫɩɨɥɶɡɭɟɦɭɸ ɛɚɡɭ ɞɚɧɧɵɯ. Ⱦɥɹ ɷɬɨɝɨ ɩɪɢɦɟɧɹɟɬɫɹ ɫɥɟɞɭɸɳɚɹ ɤɨɦɚɧɞɚ: USE databasename; Ɍɨɱɤɭ ɫ ɡɚɩɹɬɨɣ ɜ ɷɬɨɣ ɤɨɦɚɧɞɟ ɜɜɨɞɢɬɶ ɧɟ ɨɛɹɡɚɬɟɥɶɧɨ, ɧɨ ɜɫɟ ɩɪɨɱɢɟ ɤɨɦɚɧɞɵ SQL ɞɨɥɠɧɵ ɨɤɚɧɱɢɜɚɬɶɫɹ ɬɨɱɤɨɣ ɫ ɡɚɩɹɬɨɣ, ɩɨɷɬɨɦɭ ɫɥɟɞɭɟɬ ɩɪɢɜɵɤɧɭɬɶ ɤ ɟɟ ɢɫɩɨɥɶɡɨɜɚɧɢɸ. Ⱦɨ ɬɨɝɨ ɤɚɤ ɛɭɞɭɬ ɫɨɡɞɚɧɵ ɧɨɜɵɟ ɛɚɡɵ ɞɚɧɧɵɯ, ɜɨ ɜɧɨɜɶ ɜɵɩɨɥɧɟɧɧɨɣ ɢɧɫɬɚɥɥɹɰɢɢ ɢɦɟɸɬɫɹ ɬɨɥɶɤɨ ɞɜɟ ɛɚɡɵ ɞɚɧɧɵɯ: mysql ɢ test. ȿɫɥɢ ɜɵ ɬɨɥɶɤɨ ɱɬɨ ɩɨɞɤɥɸɱɢɥɢɫɶ ɤ ɫɟɪɜɟɪɭ MySQL Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 353 ɤɚɤ ɩɨɥɶɡɨɜɚɬɟɥɶ root, ɬɨ ɢɦɟɟɬɟ ɞɨɫɬɭɩ ɤ ɨɛɟɢɦ ɛɚɡɚɦ ɞɚɧɧɵɯ, ɚ ɜ ɫɥɭɱɚɟ ɩɨɞɤɥɸɱɟɧɢɹ ɩɨɞ ɢɦɟɧɟɦ ɥɸɛɨɝɨ ɞɪɭɝɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ ɜɵ ɩɨɥɭɱɢɬɟ ɞɨɫɬɭɩ ɬɨɥɶɤɨ ɤ ɛɚɡɟ ɞɚɧɧɵɯ test. Ʉɨɦɚɧɞɚ SHOW TABLES; ɩɨɡɜɨɥɹɟɬ ɩɨɥɭɱɢɬɶ ɫɩɢɫɨɤ ɜɫɟɯ ɬɚɛɥɢɰ ɜ ɢɫɩɨɥɶɡɭɟɦɨɣ ɛɚɡɟ ɞɚɧɧɵɯ. ɑɬɨɛɵ ɛɵɫɬɪɨ ɨɡɧɚɤɨɦɢɬɶɫɹ ɫɨ ɫɬɪɭɤɬɭɪɨɣ ɨɞɧɨɣ ɢɡ ɬɚɛɥɢɰ ɛɚɡɵ ɞɚɧɧɵɯ, ɦɨɠɧɨ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɤɨɦɚɧɞɨɣ SHOW COLUMNS FROM tablename;. ɗɬɚ ɤɨɦɚɧɞɚ ɜɵɜɨɞɢɬ ɢɦɟɧɚ ɜɫɟɯ ɫɬɨɥɛɰɨɜ ɫ ɭɤɚɡɚɧɢɟɦ ɬɢɩɨɜ, ɪɚɡɦɟɪɨɜ, ɩɪɢɦɟɧɹɟɦɵɯ ɩɨ ɭɦɨɥɱɚɧɢɸ ɡɧɚɱɟɧɢɣ, ɢ ɞɪɭɝɭɸ ɩɨɥɟɡɧɭɸ ɢɧɮɨɪɦɚɰɢɸ. Ⱦɥɹ ɩɪɨɫɦɨɬɪɚ ɜɫɟɯ ɡɧɚɱɟɧɢɣ ɜ ɬɚɛɥɢɰɟ ɞɨɫɬɚɬɨɱɧɨ ɜɜɟɫɬɢ ɨɩɟɪɚɬɨɪ SELECT ɛɟɡ ɨɝɪɚɧɢɱɢɬɟɥɶɧɵɯ ɭɫɥɨɜɢɣ: SELECT * FROM tablename; Ɉɞɧɚɤɨ ɩɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɩɨɞɨɛɧɨɣ ɤɨɦɚɧɞɵ ɧɟɨɛɯɨɞɢɦɨ ɫɨɛɥɸɞɚɬɶ ɨɫɬɨɪɨɠɧɨɫɬɶ, ɩɨɫɤɨɥɶɤɭ ɜ ɞɟɣɫɬɜɭɸɳɢɯ ɛɚɡɚɯ ɞɚɧɧɵɯ ɪɟɡɭɥɶɬɚɬɵ ɜɵɩɨɥɧɟɧɢɹ ɡɚɩɪɨɫɚ ɬɚɤɨɝɨ ɪɨɞɚ ɦɨɝɭɬ ɨɤɚɡɚɬɶɫɹ ɤɨɥɨɫɫɚɥɶɧɵɦɢ ɩɨ ɫɜɨɟɦɭ ɨɛɴɟɦɭ ɢ ɩɨɬɪɟɛɭɸɬ ɨɱɟɧɶ ɦɧɨɝɨ ɪɟɫɭɪɫɨɜ. ȿɫɥɢ ɭ ɜɚɫ ɟɫɬɶ ɨɫɧɨɜɚɧɢɹ ɩɨɥɚɝɚɬɶ, ɱɬɨ ɧɚɛɨɪ ɞɚɧɧɵɯ ɫɨɫɬɨɢɬ ɛɨɥɶɲɟ ɱɟɦ ɢɡ ɧɟɫɤɨɥɶɤɢɯ ɫɬɪɨɤ, ɬɨ ɫɥɟɞɭɟɬ ɩɪɟɞɩɪɢɧɹɬɶ ɞɟɣɫɬɜɢɹ ɩɨ ɨɝɪɚɧɢɱɟɧɢɸ ɨɛɥɚɫɬɢ ɞɟɣɫɬɜɢɹ ɡɚɩɪɨɫɚ. Перекрестная ссылка Ⱦɨɩɨɥɧɢɬɟɥɶɧɚɹ ɢɧɮɨɪɦɚɰɢɹ ɨ ɬɨɦ, ɤɚɤ ɩɢɫɚɬɶ ɨɩɟɪɚɬɨɪɵ SQL ɧɚɩɨɞɨɛɢɟ SELECT, INSERT ɢ ɬ.ɞ. ɩɪɢɜɟɞɟɧɚ ɜ ɝɥɚɜɟ 13. ɋɥɟɞɭɟɬ ɩɨɦɧɢɬɶ, ɱɬɨ ɨɞɧɢɦ ɢɡ ɥɭɱɲɢɯ ɫɩɨɫɨɛɨɜ ɢɫɩɪɚɜɥɟɧɢɹ ɨɲɢɛɨɤ, ɜɨɡɧɢɤɚɸɳɢɯ ɩɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɨɩɟɪɚɬɨɪɨɜ SQL ɜ ɤɨɞɟ PHP, ɫɨɫɬɨɢɬ ɜ ɨɩɪɨɛɨɜɚɧɢɢ ɷɬɢɯ ɨɩɟɪɚɬɨɪɨɜ (ɩɨɫɥɟ ɩɪɢɫɜɚɢɜɚɧɢɹ ɩɨɞɯɨɞɹɳɢɯ ɮɢɤɬɢɜɧɵɯ ɡɧɚɱɟɧɢɣ ɩɟɪɟɦɟɧɧɵɦ) ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɤɥɢɟɧɬɚ MySQL ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ, ɚ ɧɟ ɤɥɢɟɧɬɚ PHP. Ȼɨɥɟɟ ɩɨɞɪɨɛɧɵɟ ɫɜɟɞɟɧɢɹ ɨɛ ɨɬɥɚɞɤɟ ɨɩɟɪɚɬɨɪɨɜ SQL, ɩɪɢɦɟɧɹɟɦɵɯ ɜ ɤɨɞɟ PHP, ɩɪɢɜɟɞɟɧɵ ɜ ɝɥɚɜɟ 19. ɇɚɤɨɧɟɰ, ɱɬɨɛɵ ɡɚɜɟɪɲɢɬɶ ɫɟɚɧɫ ɪɚɛɨɬɵ ɫ ɤɥɢɟɧɬɫɤɨɣ ɩɪɨɝɪɚɦɦɨɣ MySQL, ɦɨɠɧɨ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɤɨɦɚɧɞɨɣ quit;. ɂ ɜ ɷɬɨɣ ɤɨɦɚɧɞɟ ɬɨɱɤɚ ɫ ɡɚɩɹɬɨɣ ɹɜɥɹɟɬɫɹ ɧɟɨɛɹɡɚɬɟɥɶɧɨɣ. ɉɨɫɥɟ ɜɜɨɞɚ ɭɤɚɡɚɧɧɨɣ ɤɨɦɚɧɞɵ ɜɵ ɫɧɨɜɚ ɜɨɡɜɪɚɬɢɬɟɫɶ ɤ ɨɛɵɱɧɨɦɭ ɩɪɢɝɥɚɲɟɧɢɸ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ. Àäìèíèñòðèðîâàíèå ó÷åòíûõ çàïèñåé MySQL ȼɚɠɧɵɦ ɮɚɤɬɨɪɨɦ ɛɟɡɨɩɚɫɧɨɣ ɢ ɷɮɮɟɤɬɢɜɧɨɣ ɷɤɫɩɥɭɚɬɚɰɢɢ MySQL ɹɜɥɹɟɬɫɹ ɩɪɚɜɢɥɶɧɨɟ ɩɪɢɦɟɧɟɧɢɟ ɫɢɫɬɟɦɵ ɩɪɚɜ ɞɨɫɬɭɩɚ, ɩɪɟɞɭɫɦɨɬɪɟɧɧɨɣ ɜ ɷɬɨɣ ɛɚɡɟ ɞɚɧɧɵɯ, ɢ ɧɚɞɥɟɠɚɳɟɟ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɯ ɫɪɟɞɫɬɜ, ɩɪɟɞɧɚɡɧɚɱɟɧɧɵɯ ɞɥɹ ɭɩɪɚɜɥɟɧɢɹ ɩɪɚɜɚɦɢ ɞɨɫɬɭɩɚ ɩɨɥɶɡɨɜɚɬɟɥɟɣ. Ȼɚɡɚ ɞɚɧɧɵɯ MySQL ɩɨɡɜɨɥɹɟɬ ɱɪɟɡɜɵɱɚɣɧɨ ɬɨɱɧɨ ɨɩɪɟɞɟɥɹɬɶ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɪɚɡɥɢɱɧɵɯ ɩɨɥɶɡɨɜɚɬɟɥɟɣ, ɤɨɬɨɪɵɟ ɩɨɞɤɥɸɱɚɸɬɫɹ ɤ ɛɚɡɟ ɞɚɧɧɵɯ ɫ ɩɨɦɨɳɶɸ ɤɥɢɟɧɬɫɤɢɯ ɩɪɨɝɪɚɦɦ, ɧɚɯɨɞɹɳɢɯɫɹ ɜ ɫɚɦɵɯ ɪɚɡɥɢɱɧɵɯ ɬɨɱɤɚɯ ɫɢɫɬɟɦɵ. ɉɪɚɜɚ ɞɨɫɬɭɩɚ ɩɨɞɪɚɡɞɟɥɹɸɬɫɹ ɧɚ ɱɟɬɵɪɟ ɧɢɫɯɨɞɹɳɢɯ ɭɪɨɜɧɹ: ɝɥɨɛɚɥɶɧɵɟ, ɛɚɡɵ ɞɚɧɧɵɯ, ɬɚɛɥɢɰɵ ɢ ɫɬɨɥɛɰɵ. ɉɨɷɬɨɦɭ ɬɟɨɪɟɬɢɱɟɫɤɢ ɩɪɟɞɭɫɦɨɬɪɟɧɚ ɜɨɡɦɨɠɧɨɫɬɶ ɪɟɝɥɚɦɟɧɬɢɪɨɜɚɬɶ ɞɨɫɬɭɩ ɤɨɧɤɪɟɬɧɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ ɞɥɹ ɡɚɩɢɫɢ ɞɚɧɧɵɯ ɬɨɥɶɤɨ ɜ ɭɤɚɡɚɧɧɵɟ ɫɬɨɥɛɰɵ ɭɤɚɡɚɧɧɵɯ ɬɚɛɥɢɰ ɭɤɚɡɚɧɧɵɯ ɛɚɡ ɞɚɧɧɵɯ ɧɚ ɭɤɚɡɚɧɧɨɦ ɫɟɪɜɟɪɟ MySQL. ɋɬɨɥɶ ɠɟ ɥɟɝɤɨ ɦɨɠɧɨ, ɧɟ ɡɚɞɭɦɵɜɚɹɫɶ, ɩɪɟɞɨɫɬɚɜɢɬɶ ɥɸɛɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɛɚɡɵ ɞɚɧɧɵɯ, ɩɨɞɤɥɸɱɚɸɳɟɦɭɫɹ ɨɬɤɭɞɚ ɭɝɨɞɧɨ, ɬɚɤɢɟ ɠɟ ɩɪɚɜɚ, ɤɚɤ ɩɨɥɶɡɨɜɚɬɟɥɸ ɛɚɡɵ ɞɚɧɧɵɯ root (ɧɨ ɬɚɤɚɹ ɨɪɝɚɧɢɡɚɰɢɹ ɡɚɳɢɬɵ ɞɨɫɬɭɩɚ ɤɚɬɟɝɨɪɢɱɟɫɤɢ ɧɟ ɪɟɤɨɦɟɧɞɭɟɬɫɹ). Ɉɱɟɜɢɞɧɨ, ɱɬɨ ɫɨɝɥɚɫɧɨ ɬɪɟɛɨɜɚɧɢɹɦ ɡɚɳɢɬɵ ɨɛɵɱɧɨ ɫɥɟɞɭɟɬ ɪɭɤɨɜɨɞɫɬɜɨɜɚɬɶɫɹ ɯɨɪɨɲɢɦ ɷɦɩɢɪɢɱɟɫɤɢɦ ɩɪɚɜɢɥɨɦ — ɩɪɟɞɨɫɬɚɜɥɹɬɶ ɤɚɠɞɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɬɨɥɶɤɨ ɦɢɧɢɦɚɥɶɧɵɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ, ɛɟɡ ɤɨɬɨɪɵɯ ɨɧ ɜɨɨɛɳɟ ɧɟ ɦɨɝ ɛɵ ɜɵɩɨɥɧɹɬɶ ɫɜɨɢ ɮɭɧɤɰɢɢ. ɇɨ ɩɪɢ ɷɬɨɦ ɧɟɨɛɯɨɞɢ- 354 ×àñòü II. PHP è MySQL ɦɨ ɭɱɢɬɵɜɚɬɶ ɢ ɨɛɨɪɨɬɧɭɸ ɫɬɨɪɨɧɭ: ɱɟɦ ɛɨɥɟɟ ɞɟɬɚɥɢɡɢɪɨɜɚɧɧɨɣ ɹɜɥɹɟɬɫɹ ɩɪɢɦɟɧɹɟɦɚɹ ɫɯɟɦɚ ɩɪɚɜ ɞɨɫɬɭɩɚ, ɬɟɦ ɦɟɞɥɟɧɧɟɟ ɜɵɩɨɥɧɹɸɬɫɹ ɜɫɟ ɢ ɤɚɠɞɵɟ ɨɩɟɪɚɬɨɪɵ INSERT, SELECT, UPDATE ɢ DELETE. ɉɪɢɱɢɧɚ ɷɬɨɝɨ ɫɨɫɬɨɢɬ ɜ ɬɨɦ, ɱɬɨ ɩɪɢ ɧɚɥɢɱɢɢ ɛɨɥɟɟ ɩɨɞɪɨɛɧɨ ɪɟɝɥɚɦɟɧɬɢɪɨɜɚɧɧɵɯ ɩɪɚɜ ɞɨɫɬɭɩɚ ɜ ɛɚɡɟ ɞɚɧɧɵɯ MySQL ɩɪɢɯɨɞɢɬɫɹ ɜɵɩɨɥɧɹɬɶ ɩɪɨɜɟɪɤɭ ɛɨɥɶɲɟɝɨ ɤɨɥɢɱɟɫɬɜɚ ɬɚɛɥɢɰ ɫ ɢɧɮɨɪɦɚɰɢɟɣ ɨ ɩɪɚɜɚɯ ɞɨɫɬɭɩɚ. Ɋɚɡɭɦɟɟɬɫɹ, ɜ ɞɟɣɫɬɜɢɬɟɥɶɧɨɫɬɢ ɧɚɛɥɸɞɚɟɦɨɟ ɩɪɢ ɷɬɨɦ ɫɧɢɠɟɧɢɟ ɩɪɨɢɡɜɨɞɢɬɟɥɶɧɨɫɬɢ ɨɬɪɢɰɚɬɟɥɶɧɨ ɨɬɪɚɠɚɟɬɫɹ ɧɚ ɪɚɛɨɬɟ ɞɚɥɟɤɨ ɧɟ ɤɚɠɞɨɝɨ ɭɡɥɚ, ɧɨ ɟɫɥɢ ɬɚɤɨɟ ɜɥɢɹɧɢɟ ɫɬɚɧɨɜɢɬɫɹ ɫɭɳɟɫɬɜɟɧɧɵɦ, ɬɨ ɧɟɨɛɯɨɞɢɦɨ ɧɚɣɬɢ ɨɩɪɟɞɟɥɟɧɧɵɣ ɤɨɦɩɪɨɦɢɫɫ ɦɟɠɞɭ ɫɬɟɩɟɧɶɸ ɡɚɳɢɬɵ ɢ ɩɪɨɢɡɜɨɞɢɬɟɥɶɧɨɫɬɶɸ. Ɉɫɧɨɜɨɣ ɫɢɫɬɟɦɵ ɩɪɚɜ ɞɨɫɬɭɩɚ MySQL ɹɜɥɹɟɬɫɹ ɬɚɛɥɢɰɚ, ɫ ɤɨɬɨɪɨɣ ɞɨɥɠɟɧ ɛɵɬɶ ɯɨɪɨɲɨ ɡɧɚɤɨɦ ɤɚɠɞɵɣ ɚɞɦɢɧɢɫɬɪɚɬɨɪ ɛɚɡɵ ɞɚɧɧɵɯ — ɬɚɛɥɢɰɚ user ɛɚɡɵ ɞɚɧɧɵɯ mysql (ɷɬɚ ɛɚɡɚ ɞɚɧɧɵɯ, ɧɚɪɹɞɭ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ test, ɩɨɫɬɚɜɥɹɟɬɫɹ ɫ ɤɚɠɞɨɣ ɢɧɫɬɚɥɥɹɰɢɟɣ MySQL). Ɋɚɫɫɦɨɬɪɢɦ ɭɩɪɨɳɟɧɧɭɸ ɜɟɪɫɢɸ ɭɤɚɡɚɧɧɨɣ ɬɚɛɥɢɰɵ (ɩɪɢɧɨɫɢɦ ɫɜɨɢ ɢɡɜɢɧɟɧɢɹ ɡɚ ɬɨ, ɱɬɨ ɫɬɪɨɤɢ ɷɬɨɣ ɬɚɛɥɢɰɵ ɩɨɤɚɡɚɧɵ ɫ ɪɚɡɛɢɜɤɨɣ ɧɚ ɞɜɟ ɩɟɱɚɬɧɵɟ ɫɬɪɨɤɢ, ɧɨ ɬɚɤ ɨɧɢ ɨɬɨɛɪɚɠɚɸɬɫɹ ɢ ɜ ɨɤɧɚɯ ɦɧɨɝɢɯ ɤɨɦɚɧɞɧɵɯ ɢɧɬɟɪɩɪɟɬɚɬɨɪɨɜ). mysql> select * from user; +-----------+------+----------+-------------+-------------+ -------------+-------------+ | Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | +-----------+------+----------+-------------+-------------+ -------------+-------------+ | localhost | root | | Y | Y | Y | Y | Y | Y | | dhcppc2 | root | | Y | Y | Y | Y | Y | Y | | localhost | | | N | N | N | N | N | N | | dhcppc2 | | | N | N | N | N | N | N | +-----------+------+----------+-------------+-------------+ -------------+-------------+ 4 rows in set (0.00 sec) Ʉɚɤ ɩɨɤɚɡɵɜɚɟɬ ɞɚɧɧɵɣ ɥɢɫɬɢɧɝ, ɜ ɛɚɡɟ ɞɚɧɧɵɯ ɢɦɟɸɬɫɹ ɞɚɧɧɵɟ ɨ ɧɟɫɤɨɥɶɤɢɯ ɯɚɪɚɤɬɟɪɧɵɯ ɝɥɨɛɚɥɶɧɵɯ ɩɪɚɜɚɯ ɞɨɫɬɭɩɚ, ɤɨɬɨɪɵɟ ɨɛɨɡɧɚɱɚɸɬɫɹ ɜ ɬɚɛɥɢɰɟ ɫ ɩɨɦɨɳɶɸ ɛɭɤɜɵ Y ɢɥɢ N. Ȼɭɤɜɚ Y ɜ ɫɬɪɨɤɟ ɬɚɛɥɢɰɵ user ɨɛɨɡɧɚɱɚɟɬ ɝɥɨɛɚɥɶɧɨɟ ɩɪɚɜɨ ɞɨɫɬɭɩɚ, ɪɚɫɩɪɨɫɬɪɚɧɹɸɳɟɟɫɹ ɧɚ ɜɫɟ ɬɚɛɥɢɰɵ ɜɫɟɯ ɛɚɡ ɞɚɧɧɵɯ ɧɚ ɪɚɫɫɦɚɬɪɢɜɚɟɦɨɦ ɫɟɪɜɟɪɟ MySQL. ȿɫɥɢ ɫɟɪɜɟɪ MySQL ɩɨɥɭɱɚɟɬ ɡɚɩɪɨɫ ɨɬ ɩɨɥɶɡɨɜɚɬɟɥɹ, ɞɥɹ ɤɨɬɨɪɨɝɨ ɡɚɞɚɧɨ ɡɧɚɱɟɧɢɟ N ɜ ɩɨɥɟ, ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɦ ɞɟɣɫɬɜɢɸ, ɩɨɩɵɬɤɚ ɜɵɩɨɥɧɟɧɢɹ ɤɨɬɨɪɨɝɨ ɩɪɟɞɩɪɢɧɹɬɚ ɩɨɥɶɡɨɜɚɬɟɥɟɦ, ɫɟɪɜɟɪ ɩɪɢɫɬɭɩɚɟɬ ɤ ɩɪɨɯɨɠɞɟɧɢɸ ɜɧɢɡ ɩɨ ɢɟɪɚɪɯɢɢ ɭɪɨɜɧɟɣ ɩɪɚɜ ɞɨɫɬɭɩɚ. ȼɧɚɱɚɥɟ ɩɪɨɢɫɯɨɞɢɬ ɩɟɪɟɯɨɞ ɤ ɬɚɛɥɢɰɟ db ɞɥɹ ɩɪɨɜɟɪɤɢ ɩɪɚɜ ɞɨɫɬɭɩɚ ɧɚ ɭɪɨɜɧɟ ɛɚɡɵ ɞɚɧɧɵɯ. Ɂɚɬɟɦ, ɟɫɥɢ ɜ ɷɬɨɣ ɬɚɛɥɢɰɟ ɬɚɤɠɟ ɨɛɧɚɪɭɠɢɜɚɸɬɫɹ ɬɨɥɶɤɨ ɡɧɚɱɟɧɢɹ N, ɩɪɨɢɫɯɨɞɢɬ ɩɟɪɟɯɨɞ ɤ ɬɚɛɥɢɰɟ tables_priv ɞɥɹ ɨɡɧɚɤɨɦɥɟɧɢɹ ɫ ɩɪɚɜɚɦɢ ɞɨɫɬɭɩɚ ɧɚ ɭɪɨɜɧɟ ɬɚɛɥɢɰɵ. ɇɚɤɨɧɟɰ, ɫɟɪɜɟɪ ɩɟɪɟɯɨɞɢɬ ɤ ɬɚɛɥɢɰɟ columns_priv ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɢɧɮɨɪɦɚɰɢɢ ɨ ɩɪɚɜɚɯ ɞɨɫɬɭɩɚ ɧɚ ɭɪɨɜɧɟ ɫɬɨɥɛɰɚ. ɂ ɬɨɥɶɤɨ ɩɨɫɥɟ ɢɫɱɟɪɩɵɜɚɸɳɟɣ ɩɪɨɜɟɪɤɢ ɜɫɟɯ ɬɚɛɥɢɰ ɫ ɢɧɮɨɪɦɚɰɢɟɣ ɨ ɩɪɚɜɚɯ ɞɨɫɬɭɩɚ ɫɟɪɜɟɪ ɫɨɨɛɳɚɟɬ ɤɥɢɟɧɬɭ ɨɛ ɨɲɢɛɤɟ ɞɨɫɬɭɩɚ. Внимание! Ⱦɚɠɟ ɟɫɥɢ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɧɚ ɭɪɨɜɧɟ ɫɬɨɥɛɰɚ ɢɥɢ ɬɚɛɥɢɰɵ ɩɪɟɞɨɫɬɚɜɥɟɧɵ ɥɢɲɶ ɟɞɢɧɫɬɜɟɧɧɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɫɪɟɞɢ ɦɧɨɝɢɯ, ɜ ɫɢɫɬɟɦɟ MySQL ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɩɪɨɜɟɪɤɚ ɭɤɚɡɚɧɧɵɯ ɬɚɛɥɢɰ ɩɪɚɜ ɞɨɫɬɭɩɚ ɞɥɹ ɜɫɟɯ ɩɨɥɶɡɨɜɚɬɟɥɟɣ. ɉɨɷɬɨɦɭ ɩɪɟɞɨɫɬɚɜɥɟɧɢɟ ɩɪɚɜ ɞɨɫɬɭɩɚ ɤ ɫɬɨɥɛɰɭ ɢɥɢ ɬɚɛɥɢɰɟ ɞɚɠɟ ɨɞɧɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɦɨɠɟɬ ɫɭɳɟɫɬɜɟɧɧɨ ɡɚɦɟɞɥɢɬɶ ɜɵɩɨɥɧɟɧɢɟ ɜɫɟɯ ɨɩɟɪɚɬɨɪɨɜ SQL ɜɫɟɯ ɩɨɥɶɡɨɜɚɬɟɥɟɣ. Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 355 Внимание! ɇɟ ɫɭɳɟɫɬɜɭɟɬ ɫɩɨɫɨɛɚ ɩɪɟɞɨɫɬɚɜɢɬɶ ɩɨɥɶɡɨɜɚɬɟɥɸ ɜɨɡɦɨɠɧɨɫɬɶ ɫɨɡɞɚɜɚɬɶ ɢɥɢ ɭɧɢɱɬɨɠɚɬɶ ɥɸɛɭɸ ɬɚɛɥɢɰɭ ɛɚɡɵ ɞɚɧɧɵɯ, ɧɟ ɩɪɟɞɨɫɬɚɜɢɜ ɬɚɤɠɟ ɷɬɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɜɨɡɦɨɠɧɨɫɬɶ ɩɨɥɧɨɫɬɶɸ ɭɧɢɱɬɨɠɚɬɶ ɪɚɫɫɦɚɬɪɢɜɚɟɦɭɸ ɛɚɡɭ ɞɚɧɧɵɯ. Ɍɟɦ ɧɟ ɦɟɧɟɟ ɦɨɠɧɨ ɡɚɩɪɟɬɢɬɶ ɩɨɥɶɡɨɜɚɬɟɥɸ ɫɨɡɞɚɜɚɬɶ ɢɥɢ ɭɧɢɱɬɨɠɚɬɶ ɞɪɭɝɢɟ ɛɚɡɵ ɞɚɧɧɵɯ ɧɚ ɬɨɦ ɠɟ ɫɟɪɜɟɪɟ. Ʉɪɨɦɟ ɬɨɝɨ, ɬɚɛɥɢɰɵ ɫ ɩɪɚɜɚɦɢ ɞɨɫɬɭɩɚ MySQL ɧɟɥɶɡɹ ɢɫɩɨɥɶɡɨɜɚɬɶ ɞɥɹ ɛɥɨɤɢɪɨɜɤɢ ɩɨɩɵɬɨɤ ɩɨɞɤɥɸɱɟɧɢɹ ɫ ɨɩɪɟɞɟɥɟɧɧɵɯ IPɚɞɪɟɫɨɜ ɢɥɢ ɯɨɫɬɨɜ. Ⱦɥɹ ɞɨɛɚɜɥɟɧɢɹ ɢɥɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɩɪɚɜ ɞɨɫɬɭɩɚ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɜ ɛɚɡɟ ɞɚɧɧɵɯ MySQL ɦɨɝɭɬ ɩɪɢɦɟɧɹɬɶɫɹ ɞɜɚ ɪɚɡɧɵɯ ɫɩɨɫɨɛɚ (ɩɪɢ ɭɫɥɨɜɢɢ, ɱɬɨ ɦɨɞɢɮɢɤɚɰɢɟɣ ɩɪɚɜ ɞɨɫɬɭɩɚ ɡɚɧɢɦɚɟɬɫɹ ɩɨɥɶɡɨɜɚɬɟɥɶ ɛɚɡɵ ɞɚɧɧɵɯ root): ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨɟ ɜɵɩɨɥɧɟɧɢɟ ɨɩɟɪɚɬɨɪɨɜ SQL (ɧɚɩɪɢɦɟɪ, ɜɜɨɞ ɛɭɤɜɵ Y ɜɪɭɱɧɭɸ ɜ ɤɚɠɞɨɟ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɟ ɩɨɥɟ ɤɚɠɞɨɣ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɣ ɬɚɛɥɢɰɵ ɩɪɚɜ ɞɨɫɬɭɩɚ) ɢɥɢ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɫɢɧɬɚɤɫɢɱɟɫɤɢɯ ɤɨɧɫɬɪɭɤɰɢɣ GRANT ɢ REVOKE. ɉɨɫɥɟɞɧɢɣ ɫɩɨɫɨɛ ɹɜɥɹɟɬɫɹ ɛɨɥɟɟ ɥɟɝɤɢɦ ɢ ɦɟɧɟɟ ɨɩɚɫɧɵɦ, ɟɫɥɢ ɞɨɩɭɳɟɧɚ ɧɟɛɨɥɶɲɚɹ ɨɲɢɛɤɚ, ɩɨɫɤɨɥɶɤɭ ɜ ɛɨɥɶɲɢɧɫɬɜɟ ɫɥɭɱɚɟɜ ɩɨɩɵɬɤɚ ɜɵɩɨɥɧɟɧɢɹ ɨɲɢɛɨɱɧɨɝɨ ɡɚɩɪɨɫɚ ɨɤɨɧɱɢɬɫɹ ɧɟɭɞɚɱɟɣ ɫ ɫɨɨɛɳɟɧɢɟɦ ɨɛ ɨɲɢɛɤɟ SQL, ɧɨ ɩɪɢ ɷɬɨɦ ɧɟ ɜɨɡɧɢɤɧɟɬ ɩɪɨɛɟɥ ɜ ɫɢɫɬɟɦɟ ɡɚɳɢɬɵ. ɑɬɨɛɵ ɜɜɟɫɬɢ ɢɧɮɨɪɦɚɰɢɸ ɨ ɧɨɜɨɦ ɩɨɥɶɡɨɜɚɬɟɥɟ MySQL, ɦɨɠɧɨ ɩɪɢɦɟɧɢɬɶ ɫɥɟɞɭɸɳɢɣ ɨɩɟɪɚɬɨɪ: GRANT priv_type [(column1, column2, column3)] ON database.[table] TO user@host IDENTIFIED BY 'new_password'; Ɂɞɟɫɶ ɞɚɧɧɵɟ ɨ ɫɬɨɥɛɰɚɯ (column) ɢ ɬɚɛɥɢɰɚɯ (table) ɹɜɥɹɸɬɫɹ ɧɟɨɛɹɡɚɬɟɥɶɧɵɦɢ, ɚ ɫ ɩɨɦɨɳɶɸ ɫɩɢɫɤɚ, ɪɚɡɞɟɥɟɧɧɨɝɨ ɡɚɩɹɬɵɦɢ, ɦɨɝɭɬ ɛɵɬɶ ɡɚɞɚɧɵ ɞɨɩɨɥɧɢɬɟɥɶɧɵɟ ɫɜɟɞɟɧɢɹ ɨ ɬɢɩɚɯ ɩɪɚɜ ɞɨɫɬɭɩɚ priv_types. Ɍɢɩɵ ɩɪɚɜ ɞɨɫɬɭɩɚ ɢ ɨɛɥɚɫɬɢ ɢɯ ɞɟɣɫɬɜɢɹ ɩɨɤɚɡɚɧɵ ɜ ɬɚɛɥ. 14.1. Òàáëèöà 14.1. Îáëàñòè äåéñòâèÿ ïðàâ äîñòóïà MySQL Ïðàâà äîñòóïà Ãëîáàëüíûå Áàçû äàííûõ ALL 9 9 ALTER 9 9 9 CREATE 9 9 9 CREATE TEMPORARY TABLE 9 9 9 DELETE 9 9 9 DROP 9 9 9 EXECUTE 9 9 FILE 9 9 INDEX 9 9 INSERT 9 9 LOCK TABLES 9 9 PROCESS 9 9 REFERENCES 9 9 RELOAD 9 9 REPLICATION CLIENT 9 REPLICATION SLAVE 9 SELECT 9 356 9 Òàáëèöû Ñòîëáöà 9 9 9 9 ×àñòü II. PHP è MySQL Ɉɤɨɧɱɚɧɢɟ ɬɚɛɥ. 14.1 Ïðàâà äîñòóïà Ãëîáàëüíûå Áàçû äàííûõ SHOW DATABASES 9 SHUTDOWN 9 SUPER 9 9 UPDATE 9 9 USAGE 9 9 GRANT OPTION 9 9 Òàáëèöû Ñòîëáöà 9 9 9 Ɉɱɟɜɢɞɧɨ, ɱɬɨ ɧɟɬ ɫɦɵɫɥɚ ɩɵɬɚɬɶɫɹ ɩɪɟɞɨɫɬɚɜɢɬɶ ɤɚɤɨɦɭ-ɥɢɛɨ ɩɨɥɶɡɨɜɚɬɟɥɸ ɩɪɚɜɚ ɞɨɫɬɭɩɚ SHUTDOWN ɧɚ ɭɪɨɜɧɟ ɬɚɛɥɢɰɵ. ɉɪɢ ɷɬɨɦ ɩɪɨɫɬɨ ɜɵɪɚɛɚɬɵɜɚɟɬɫɹ ɫɨɨɛɳɟɧɢɟ ɨɛ ɨɲɢɛɤɟ, ɜ ɤɨɬɨɪɨɦ ɩɪɟɞɥɚɝɚɟɬɫɹ ɨɡɧɚɤɨɦɢɬɶɫɹ ɫ ɞɨɤɭɦɟɧɬɚɰɢɟɣ. ȿɫɥɢ ɩɪɟɞɨɫɬɚɜɥɟɧɵ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ALL ɧɚ ɭɪɨɜɧɟ ɫɬɨɥɛɰɚ, ɬɚɛɥɢɰɵ ɢɥɢ ɛɚɡɵ ɞɚɧɧɵɯ, ɬɨ ɩɨɥɶɡɨɜɚɬɟɥɶ ɩɨɥɭɱɚɟɬ ɜɨɡɦɨɠɧɨɫɬɶ ɩɪɢɦɟɧɹɬɶ ɬɨɥɶɤɨ ɬɨɬ ɧɚɛɨɪ ɩɪɚɜ ɞɨɫɬɭɩɚ, ɤɨɬɨɪɵɣ ɫɨɨɬɜɟɬɫɬɜɭɟɬ ɭɤɚɡɚɧɧɨɦɭ ɭɪɨɜɧɸ. ɇɟɨɛɯɨɞɢɦɨ ɫɨɛɥɸɞɚɬɶ ɢɫɤɥɸɱɢɬɟɥɶɧɭɸ ɨɫɬɨɪɨɠɧɨɫɬɶ ɩɪɢ ɩɪɟɞɨɫɬɚɜɥɟɧɢɢ ɩɨɥɶɡɨɜɚɬɟɥɹɦ ɫɥɟɞɭɸɳɢɯ ɩɪɚɜ ɞɨɫɬɭɩɚ, ɩɨɫɤɨɥɶɤɭ ɷɬɢ ɩɪɚɜɚ ɜɫɟ ɛɟɡ ɢɫɤɥɸɱɟɧɢɹ ɹɜɥɹɸɬɫɹ ɨɩɚɫɧɵɦɢ: GRANT, ALTER, CREATE, DROP, FILE, SHUTDOWN, PROCESS. ɇɚ ɩɪɨɢɡɜɨɞɫɬɜɟ ɬɚɤɢɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɧɟ ɬɪɟɛɭɸɬɫɹ ɧɢ ɨɞɧɨɦɭ ɨɛɵɱɧɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɛɚɡɵ ɞɚɧɧɵɯ, ɨɫɨɛɟɧɧɨ ɩɨɥɶɡɨɜɚɬɟɥɸ PHP. ɋɢɧɬɚɤɫɢɱɟɫɤɚɹ ɤɨɧɫɬɪɭɤɰɢɹ ɨɩɟɪɚɬɨɪɚ ɨɬɦɟɧɵ ɩɪɚɜ ɞɨɫɬɭɩɚ ɹɜɥɹɟɬɫɹ ɜɟɫɶɦɚ ɩɨɯɨɠɟɣ ɧɚ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɨɩɟɪɚɬɨɪ ɩɪɟɞɨɫɬɚɜɥɟɧɢɹ ɩɪɚɜ ɞɨɫɬɭɩɚ, ɧɨ ɩɪɨɳɟ ɧɟɝɨ: REVOKE priv_type [(column1, column2, column3)] ON database[.table] FROM user@host; ɉɨɫɥɟ ɩɪɟɞɨɫɬɚɜɥɟɧɢɹ ɢɥɢ ɨɬɦɟɧɵ ɩɪɚɜ ɞɨɫɬɭɩɚ ɞɥɹ ɥɸɛɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ ɧɟɨɛɯɨɞɢɦɨ ɜɵɧɭɞɢɬɶ ɛɚɡɭ ɞɚɧɧɵɯ ɜɵɩɨɥɧɢɬɶ ɩɟɪɟɡɚɝɪɭɡɤɭ ɜ ɩɚɦɹɬɶ ɧɨɜɵɯ ɞɚɧɧɵɯ ɨ ɩɪɚɜɚɯ ɞɨɫɬɭɩɚ. Ⱦɥɹ ɷɬɨɝɨ ɬɪɟɛɭɟɬɫɹ ɜɜɟɫɬɢ ɤɨɦɚɧɞɭ FLUSH PRIVILEGES. Ɇɨɠɧɨ ɬɚɤɠɟ ɨɫɬɚɧɨɜɢɬɶ ɢ ɫɧɨɜɚ ɡɚɩɭɫɬɢɬɶ ɫɟɪɜɟɪ, ɧɨ ɬɚɤɨɟ ɪɟɲɟɧɢɟ ɜɨ ɦɧɨɝɢɯ ɨɛɫɬɨɹɬɟɥɶɫɬɜɚɯ ɹɜɥɹɟɬɫɹ ɩɪɚɤɬɢɱɟɫɤɢ ɧɟɩɪɢɦɟɧɢɦɵɦ. Ȼɟɡɭɫɥɨɜɧɨ, ɢɡɥɨɠɟɧɧɵɟ ɜɵɲɟ ɫɜɟɞɟɧɢɹ ɜɩɨɥɧɟ ɞɨɫɬɭɩɧɵ ɞɥɹ ɜɨɫɩɪɢɹɬɢɹ, ɧɨ ɧɟ ɞɚɸɬ ɨɬɜɟɬɚ ɧɚ ɬɚɤɨɣ ɜɨɩɪɨɫ: “Ʉɚɤɢɟ ɠɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɞɨɥɠɧɵ ɛɵɬɶ ɮɚɤɬɢɱɟɫɤɢ ɩɪɟɞɨɫɬɚɜɥɟɧɵ ɞɟɣɫɬɜɭɸɳɢɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ PHP?” Ɋɚɫɫɦɨɬɪɢɦ ɧɟɤɨɬɨɪɵɟ ɫɥɭɱɚɢ, ɤɨɬɨɪɵɟ ɱɚɫɬɨ ɜɫɬɪɟɱɚɸɬɫɹ ɧɚ ɩɪɚɤɬɢɤɟ. Ëîêàëüíûé ñåðâåð, ïðèìåíÿåìûé äëÿ ðàçðàáîòêè ȿɫɥɢ ɞɨɫɬɭɩ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɢɫɤɥɸɱɢɬɟɥɶɧɨ ɥɨɤɚɥɶɧɨ, ɨɫɨɛɟɧɧɨ ɫ ɤɨɦɩɶɸɬɟɪɚ, ɤɨɬɨɪɵɣ ɧɟ ɩɨɞɤɥɸɱɟɧ ɩɨɫɬɨɹɧɧɨ ɤ ɂɧɬɟɪɧɟɬ ɢɥɢ ɧɚɞɟɠɧɨ ɫɩɪɹɬɚɧ ɡɚ ɯɨɪɨɲɢɦ ɛɪɚɧɞɦɚɭɷɪɨɦ, ɬɨ ɩɪɢɦɟɧɢɦɵ ɩɪɚɤɬɢɱɟɫɤɢ ɥɸɛɵɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ. ȿɫɥɢ ɜ ɯɨɞɟ ɪɚɡɪɚɛɨɬɤɢ ɬɪɟɛɭɟɬɫɹ ɩɪɨɜɨɞɢɬɶ ɷɤɫɩɟɪɢɦɟɧɬɵ ɫɨ ɫɯɟɦɨɣ ɛɚɡɵ ɞɚɧɧɵɯ, ɬɨ ɧɚɢɛɨɥɟɟ ɩɨɞɯɨɞɹɳɢɦ ɹɜɥɹɟɬɫɹ ɢɦɟɧɧɨ ɬɚɤɚɹ ɤɨɧɮɢɝɭɪɚɰɢɹ, ɩɨɷɬɨɦɭ ɪɚɡɪɚɛɨɬɱɢɤɭ, ɤɪɨɦɟ ɨɛɵɱɧɵɯ ɩɪɚɜ ɞɨɫɬɭɩɚ ɞɥɹ ɜɵɩɨɥɧɟɧɢɹ ɨɩɟɪɚɰɢɣ SELECT, INSERT ɢ UPDATE, ɦɨɝɭɬ ɛɵɬɶ ɩɪɟɞɨɫɬɚɜɥɟɧɵ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɧɚɩɨɞɨɛɢɟ ALTER, CREATE, DELETE ɢ DROP. ɉɪɢ ɬɚɤɢɯ ɨɛɫɬɨɹɬɟɥɶɫɬɜɚɯ ɦɧɨɝɢɟ ɚɞɦɢɧɢɫɬɪɚɬɨɪɵ ɫɱɢɬɚɸɬ ɩɪɢɟɦɥɟɦɵɦ ɩɪɟɞɨɫɬɚɜɢɬɶ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ALL PRIVILEGES ɤ ɨɩɪɟɞɟɥɟɧɧɨɣ ɛɚɡɟ ɞɚɧɧɵɯ ɥɨɤɚɥɶɧɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ, ɤɚɤ ɩɨɤɚɡɚɧɨ ɧɢɠɟ. GRANT ALL PRIVILEGES on database.* TO username@localhost IDENTIFIED BY 'password'; Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 357 Àâòîíîìíûé Web-óçåë Ȼɚɡɚ ɞɚɧɧɵɯ, ɧɚɯɨɞɹɳɚɹɫɹ ɧɚ ɨɬɞɟɥɶɧɨɦ ɯɨɫɬɟ, ɩɨ-ɜɢɞɢɦɨɦɭ, ɞɨɥɠɧɚ ɛɭɞɟɬ ɩɪɢɧɢɦɚɬɶ ɡɚɩɪɨɫɵ ɧɚ ɭɫɬɚɧɨɜɥɟɧɢɟ ɫɨɟɞɢɧɟɧɢɣ ɨɬ ɦɧɨɝɨɱɢɫɥɟɧɧɵɯ Web-ɫɟɪɜɟɪɨɜ, ɧɚɯɨɞɹɳɢɯɫɹ ɜ ɬɨɦ ɠɟ ɞɨɦɟɧɟ. ɇɚ ɩɪɨɢɡɜɨɞɫɬɜɟ ɞɥɹ ɜɫɟɯ ɫɟɪɜɟɪɧɵɯ ɤɨɦɩɶɸɬɟɪɨɜ ɞɨɥɠɧɵ ɩɪɟɞɨɫɬɚɜɥɹɬɶɫɹ ɥɢɲɶ ɩɪɚɜɚ ɞɨɫɬɭɩɚ SELECT, INSERT, UPDATE ɢ, ɜɨɡɦɨɠɧɨ, DELETE, ɯɨɬɹ ɜɨ ɦɧɨɝɢɯ ɫɢɫɬɟɦɚɯ ɭɞɚɥɟɧɢɟ ɞɚɧɧɵɯ ɮɚɤɬɢɱɟɫɤɢ ɧɟ ɩɪɨɢɫɯɨɞɢɬ, ɩɨɷɬɨɦɭ ɭɪɨɜɟɧɶ ɛɟɡɨɩɚɫɧɨɫɬɢ ɧɟɦɧɨɝɨ ɩɨɜɵɲɚɟɬɫɹ, ɟɫɥɢ ɩɪɚɜɨ ɞɨɫɬɭɩɚ DELETE ɧɟ ɩɪɟɞɨɫɬɚɜɥɹɟɬɫɹ. Ʉɪɨɦɟ ɬɨɝɨ, ɩɨɫɤɨɥɶɤɭ ɤɨɥɢɱɟɫɬɜɨ ɛɚɡ ɞɚɧɧɵɯ, ɩɨɞɤɥɸɱɚɸɳɢɯɫɹ ɤ ɩɪɨɢɡɜɨɞɫɬɜɟɧɧɨɣ ɛɚɡɟ ɞɚɧɧɵɯ ɚɜɬɨɧɨɦɧɨɝɨ Web-ɭɡɥɚ, ɩɨɜɢɞɢɦɨɦɭ, ɧɟ ɫɥɢɲɤɨɦ ɜɟɥɢɤɨ, ɬɨ ɩɪɢɦɟɧɟɧɢɟ ɝɥɨɛɚɥɶɧɵɯ ɩɪɚɜ ɞɨɫɬɭɩɚ ɩɪɢɜɨɞɢɬ ɤ ɭɫɤɨɪɟɧɢɸ ɪɚɛɨɬɵ ɢ ɜɦɟɫɬɟ ɫ ɬɟɦ ɧɟ ɫɨɡɞɚɟɬ ɛɨɥɟɟ ɡɧɚɱɢɬɟɥɶɧɵɣ ɪɟɚɥɶɧɵɣ ɪɢɫɤ ɧɚɪɭɲɟɧɢɹ ɡɚɳɢɬɵ. ɉɨɷɬɨɦɭ ɞɨɩɭɫɬɢɦɵɣ ɨɩɟɪɚɬɨɪ ɩɪɟɞɨɫɬɚɜɥɟɧɢɹ ɩɪɚɜ ɞɨɫɬɭɩɚ ɦɨɠɟɬ ɜɵɝɥɹɞɟɬɶ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: GRANT SELECT, INSERT, UPDATE ON *.* TO phpdbuser@%.example.com IDENTIFIED BY 'password'; Ɍɟɦ ɧɟ ɦɟɧɟɟ ɜ ɩɨɞɨɛɧɨɣ ɫɢɬɭɚɰɢɢ ɱɚɳɟ ɜɫɟɝɨ ɢɫɩɨɥɶɡɭɟɬɫɹ ɬɚɤɠɟ ɪɟɩɥɢɤɚɰɢɹ ɩɨ ɩɪɢɧɰɢɩɭ “ɜɟɞɭɳɢɣ–ɜɟɞɨɦɵɣ”. ɑɚɫɬɨ ɩɨɞɨɛɧɵɟ ɤɥɚɫɬɟɪɵ ɛɚɡ ɞɚɧɧɵɯ MySQL ɢɦɟɸɬ ɬɚɤɭɸ ɤɨɧɮɢɝɭɪɚɰɢɸ, ɱɬɨ ɜɫɟ ɡɚɩɪɨɫɵ ɧɚ ɜɵɩɨɥɧɟɧɢɟ ɨɩɟɪɚɰɢɣ ɡɚɩɢɫɢ ɩɨɫɬɭɩɚɸɬ ɜ ɜɟɞɭɳɭɸ ɛɚɡɭ ɞɚɧɧɵɯ, ɧɨ ɜɟɞɨɦɵɟ ɛɚɡɵ ɞɚɧɧɵɯ ɧɟ ɜɵɩɨɥɧɹɸɬ ɧɢɤɚɤɢɯ ɞɪɭɝɢɯ ɞɟɣɫɬɜɢɣ, ɤɪɨɦɟ ɨɱɟɧɶ ɛɵɫɬɪɨɝɨ ɨɛɫɥɭɠɢɜɚɧɢɹ ɨɩɟɪɚɰɢɣ ɱɬɟɧɢɹ. ȼ ɬɚɤɨɦ ɫɥɭɱɚɟ ɜ ɤɚɠɞɨɣ ɜɟɞɨɦɨɣ ɛɚɡɟ ɞɚɧɧɵɯ ɩɪɟɞɨɫɬɚɜɥɹɸɬɫɹ ɬɨɥɶɤɨ ɩɪɚɜɚ ɞɨɫɬɭɩɚ SELECT, ɚ ɜ ɜɟɞɭɳɟɣ ɛɚɡɟ ɞɚɧɧɵɯ ɩɪɟɞɨɫɬɚɜɥɹɸɬɫɹ ɬɨɥɶɤɨ ɩɪɚɜɚ INSERT ɢ UPDATE; ɩɪɢ ɷɬɨɦ, ɜɨɡɦɨɠɧɨ, ɷɬɢ ɩɪɚɜɚ ɧɚɡɧɚɱɚɸɬɫɹ ɞɜɭɦ ɪɚɡɧɵɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ ɛɚɡɵ ɞɚɧɧɵɯ. Web-óçåë íà ðàçäåëÿåìîì õîñòå Ⱦɥɹ ɩɪɨɜɚɣɞɟɪɚ ɂɧɬɟɪɧɟɬ, ɩɪɟɞɨɫɬɚɜɥɹɸɳɟɝɨ ɪɚɡɞɟɥɹɟɦɵɣ ɯɨɫɬɢɧɝ, ɢɥɢ ɞɥɹ ɡɚɤɚɡɱɢɤɚ, ɪɚɡɦɟɫɬɢɜɲɟɝɨ ɫɜɨɣ Web-ɭɡɟɥ ɧɚ ɪɚɡɞɟɥɹɟɦɨɦ ɯɨɫɬɟ, ɜɚɠɧɟɟ ɞɨɛɢɬɶɫɹ ɜɵɫɨɤɨɣ ɫɬɟɩɟɧɢ ɡɚɳɢɬɵ, ɱɟɦ ɜɵɫɨɤɨɣ ɩɪɨɢɡɜɨɞɢɬɟɥɶɧɨɫɬɢ. ɇɢ ɩɪɢ ɤɚɤɢɯ ɨɛɫɬɨɹɬɟɥɶɫɬɜɚɯ ɧɟɥɶɡɹ ɞɨɩɭɫɬɢɬɶ, ɱɬɨɛɵ ɨɞɢɧ ɢɡ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɢɦɟɥ ɜɨɡɦɨɠɧɨɫɬɶ ɦɚɧɢɩɭɥɢɪɨɜɚɬɶ ɞɚɧɧɵɦɢ ɢɥɢ ɭɞɚɥɹɬɶ ɞɚɧɧɵɟ, ɩɪɢɧɚɞɥɟɠɚɳɢɟ ɞɪɭɝɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ. ȿɫɥɢ ɞɥɹ ɤɚɠɞɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ ɧɟ ɩɪɟɞɭɫɦɨɬɪɟɧ ɫɜɨɣ ɫɨɛɫɬɜɟɧɧɵɣ ɷɤɡɟɦɩɥɹɪ MySQL, ɪɚɛɨɬɚɸɳɢɣ ɱɟɪɟɡ ɨɬɞɟɥɶɧɵɣ ɩɨɪɬ, ɬɨ ɚɞɦɢɧɢɫɬɪɚɬɨɪ ɩɪɨɜɚɣɞɟɪɚ ɂɧɬɟɪɧɟɬ, ɩɪɟɞɨɫɬɚɜɥɹɸɳɟɝɨ ɪɚɡɞɟɥɹɟɦɵɣ ɯɨɫɬɢɧɝ, ɧɟ ɞɨɥɠɟɧ ɪɚɡɪɟɲɚɬɶ ɩɨɥɶɡɨɜɚɬɟɥɹɦ ɜɵɩɨɥɧɹɬɶ ɝɥɨɛɚɥɶɧɵɟ ɨɩɟɪɚɰɢɢ ɫɨɡɞɚɧɢɹ ɢɥɢ ɭɞɚɥɟɧɢɹ ɨɛɴɟɤɬɨɜ ɛɚɡɵ ɞɚɧɧɵɯ. Ɉɱɟɜɢɞɧɨ, ɱɬɨ ɧɟ ɫɭɳɟɫɬɜɭɟɬ ɭɞɨɛɧɨɝɨ ɫɩɨɫɨɛɚ ɡɚɩɪɟɬɢɬɶ ɫɨɡɞɚɧɢɟ ɢɥɢ ɭɞɚɥɟɧɢɟ ɬɚɛɥɢɰ, ɩɨɫɤɨɥɶɤɭ (ɤɚɤ ɛɵɥɨ ɨɩɢɫɚɧɨ ɜɵɲɟ) ɧɚɥɢɱɢɟ ɭ ɩɨɥɶɡɨɜɚɬɟɥɹ ɬɚɤɢɯ ɩɪɚɜ ɜɥɟɱɟɬ ɡɚ ɫɨɛɨɣ ɬɨ, ɱɬɨ ɩɨɥɶɡɨɜɚɬɟɥɶ ɩɨɥɭɱɚɟɬ ɬɚɤɠɟ ɜɨɡɦɨɠɧɨɫɬɶ ɭɞɚɥɢɬɶ ɩɪɢ ɠɟɥɚɧɢɢ ɫɜɨɸ ɫɨɛɫɬɜɟɧɧɭɸ ɛɚɡɭ ɞɚɧɧɵɯ. Ⱦɟɥɨ ɨɛɫɬɨɢɬ ɢɦɟɧɧɨ ɬɚɤ — ɟɫɥɢ ɩɨɥɶɡɨɜɚɬɟɥɢ ɢɦɟɸɬ ɩɪɚɜɨ ɨɩɪɟɞɟɥɹɬɶ ɧɨɜɵɟ ɬɚɛɥɢɰɵ, ɚ ɬɚɤɨɝɨ ɩɪɚɜɚ ɜ ɭɤɚɡɚɧɧɨɣ ɫɢɬɭɚɰɢɢ ɢɯ, ɛɟɡɭɫɥɨɜɧɨ, ɧɟɥɶɡɹ ɥɢɲɚɬɶ, ɬɨ ɧɟ ɨɫɬɚɟɬɫɹ ɩɪɢɟɦɥɟɦɨɝɨ ɫɩɨɫɨɛɚ ɡɚɳɢɬɢɬɶ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɨɬ ɨɲɢɛɤɢ, ɜ ɪɟɡɭɥɶɬɚɬɟ ɤɨɬɨɪɨɣ ɦɨɝɭɬ ɛɵɬɶ ɭɧɢɱɬɨɠɟɧɵ ɜɫɟ ɢɯ ɞɚɧɧɵɟ ɫ ɩɨɦɨɳɶɸ ɟɞɢɧɫɬɜɟɧɧɨɣ ɤɨɦɚɧɞɵ! ȼ ɷɬɨɦ ɡɚɤɥɸɱɚɟɬɫɹ ɨɛɨɪɨɬɧɚɹ ɫɬɨɪɨɧɚ ɭɞɨɛɫɬɜɚ ɫɨɡɞɚɧɢɹ ɨɛɴɟɤɬɨɜ ɜ ɛɚɡɟ ɞɚɧɧɵɯ MySQL. ɇɨ ɚɞɦɢɧɢɫɬɪɚɬɨɪ ɛɚɡɵ ɞɚɧɧɵɯ ɦɨɠɟɬ ɢ ɞɚɠɟ ɨɛɹɡɚɧ ɩɪɟɞɨɬɜɪɚɬɢɬɶ ɫɢɬɭɚɰɢɸ, ɜ ɤɨɬɨɪɨɣ ɩɨɥɶɡɨɜɚɬɟɥɢ ɩɨɥɭɱɢɥɢ ɛɵ ɜɨɡɦɨɠɧɨɫɬɶ ɩɪɨɞɟɥɵɜɚɬɶ ɬɚɤɢɟ ɠɟ ɨɩɟɪɚɰɢɢ ɫ ɞɚɧɧɵɦɢ ɞɪɭɝɢɯ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɧɚ ɬɨɦ ɠɟ ɫɟɪɜɟɪɟ. ɉɪɨɜɚɣɞɟɪɵ ɂɧɬɟɪɧɟɬ ɧɟ ɞɨɥɠɧɵ ɢɫɩɨɥɶɡɨɜɚɬɶ ɩɨɞɫɬɚɧɨɜɨɱɧɵɟ ɫɢɦɜɨɥɵ ɞɥɹ ɨɛɨɡɧɚɱɟɧɢɹ ɢɦɟɧ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɢɥɢ ɢɦɟɧ ɯɨɫɬɨɜ. Ⱦɥɹ ɤɚɠɞɨɣ ɭɱɟɬɧɨɣ ɡɚɩɢɫɢ ɩɨɥɶɡɨɜɚɬɟɥɹ ɞɨɥɠɧɨ ɛɵɬɶ ɩɪɟɞɭɫɦɨɬɪɟɧɨ ɩɨɞɤɥɸɱɟɧɢɟ ɫ ɨɞɧɨɝɨ ɢ ɬɨɥɶɤɨ ɨɞɧɨɝɨ ɫɟɪɜɟɪɚ ɜ ɩɪɨɫɬɪɚɧɫɬɜɟ ɢɦɟɧ ɞɨ- 358 ×àñòü II. PHP è MySQL ɦɟɧɚ. Ⱦɥɹ ɩɪɢɦɟɧɟɧɢɹ ɫɩɨɫɨɛɚ ɩɨɞɤɥɸɱɟɧɢɹ, ɩɪɟɞɭɫɦɚɬɪɢɜɚɸɳɟɝɨ ɩɪɢɟɦ ɤɥɢɟɧɬɫɤɢɯ ɡɚɩɪɨɫɨɜ MySQL ɧɚ ɭɫɬɚɧɨɜɥɟɧɢɟ ɫɨɟɞɢɧɟɧɢɹ ɢɡ-ɡɚ ɩɪɟɞɟɥɨɜ ɛɪɚɧɞɦɚɭɷɪɚ, ɧɟɬ ɧɢɤɚɤɢɯ ɩɪɢɟɦɥɟɦɵɯ ɨɫɧɨɜɚɧɢɣ. Ⱦɟɥɨ ɜ ɬɨɦ, ɱɬɨ ɩɨɥɶɡɨɜɚɬɟɥɹɦ ɞɥɹ ɩɪɨɜɟɞɟɧɢɹ ɦɚɧɢɩɭɥɹɰɢɣ ɫ ɢɯ ɛɚɡɨɣ ɞɚɧɧɵɯ ɞɨɥɠɧɨ ɛɵɬɶ ɜɩɨɥɧɟ ɞɨɫɬɚɬɨɱɧɨ ɩɪɟɞɨɫɬɚɜɢɬɶ ɜɨɡɦɨɠɧɨɫɬɶ ɩɨɞɤɥɸɱɟɧɢɹ ɫ ɩɨɦɨɳɶɸ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ ssh ɤ ɢɯ ɪɚɡɞɟɥɹɟɦɨɦɭ ɩɪɨɫɬɪɚɧɫɬɜɭ ɯɨɫɬɢɧɝɚ; ɟɳɟ ɨɞɢɧ ɜɚɪɢɚɧɬ ɫɨɫɬɨɢɬ ɜ ɩɪɟɞɨɫɬɚɜɥɟɧɢɢ ɩɨɥɶɡɨɜɚɬɟɥɹɦ ɜɨɡɦɨɠɧɨɫɬɢ ɢɫɩɨɥɶɡɨɜɚɬɶ ɤɚɤɨɟ-ɥɢɛɨ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɟ ɫɪɟɞɫɬɜɨ ɫ ɝɪɚɮɢɱɟɫɤɢɦ ɢɧɬɟɪɮɟɣɫɨɦ. ɉɨɷɬɨɦɭ ɜ ɞɚɧɧɨɣ ɫɢɬɭɚɰɢɢ ɱɚɳɟ ɜɫɟɝɨ ɩɪɢɦɟɧɹɟɬɫɹ ɬɚɤɨɣ ɨɩɟɪɚɬɨɪ ɩɪɟɞɨɫɬɚɜɥɟɧɢɹ ɩɪɚɜ ɞɨɫɬɭɩɚ: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON database.* TO [email protected] IDENTIFIED BY 'password'; Ʉɪɨɦɟ ɬɨɝɨ, ɧɚ ɪɚɡɞɟɥɹɟɦɵɯ ɯɨɫɬɚɯ ɱɚɫɬɨ ɢɫɩɨɥɶɡɭɟɬɫɹ ɬɚɤɨɣ ɧɟɞɨɩɭɫɬɢɦɵɣ ɦɟɬɨɞ: ɩɨɥɶɡɨɜɚɬɟɥɸ ɪɚɡɪɟɲɚɸɬ ɢɥɢ ɞɚɠɟ ɬɪɟɛɭɸɬ ɨɬ ɧɟɝɨ ɩɨɜɬɨɪɧɨ ɩɪɢɦɟɧɹɬɶ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢ ɩɚɪɨɥɶ ɞɨɦɟɧɚ ɜ ɤɚɱɟɫɬɜɟ ɢɦɟɧɢ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢ ɩɚɪɨɥɹ MySQL. Ɍɚɤɨɣ ɦɟɬɨɞ ɹɜɥɹɟɬɫɹ ɧɟɞɨɩɭɫɬɢɦɵɦ ɢ ɦɨɠɟɬ ɫɬɚɬɶ ɩɪɢɱɢɧɨɣ ɜɨɡɧɢɤɧɨɜɟɧɢɹ ɩɪɨɛɥɟɦ, ɧɟ ɩɨɞɞɚɸɳɢɯɫɹ ɨɩɢɫɚɧɢɸ. ɉɨɷɬɨɦɭ, ɟɫɥɢ ɜɚɲ ɩɪɨɜɚɣɞɟɪ ɂɧɬɟɪɧɟɬ ɞɨɩɭɫɤɚɟɬ ɩɪɢɦɟɧɟɧɢɟ ɬɚɤɨɝɨ ɦɟɬɨɞɚ, ɚɜɬɨɪɵ ɪɟɤɨɦɟɧɞɭɸɬ ɧɟɦɟɞɥɟɧɧɨ ɩɟɪɟɣɬɢ ɧɚ ɞɪɭɝɨɣ ɭɡɟɥ, ɩɪɟɞɨɫɬɚɜɥɹɸɳɢɣ Web-ɯɨɫɬɢɧɝ. Ïðîãðàììà PHPMyAdmin Ȼɟɡɭɫɥɨɜɧɨ, ɚɜɬɨɪɵ ɪɟɤɨɦɟɧɞɭɸɬ ɨɡɧɚɤɨɦɢɬɶɫɹ ɫ ɤɥɢɟɧɬɫɤɨɣ ɩɪɨɝɪɚɦɦɨɣ MySQL, ɢɦɟɸɳɟɣ ɢɧɬɟɪɮɟɣɫ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ, ɢ ɢɫɩɨɥɶɡɨɜɚɬɶ ɟɟ ɜ ɦɚɤɫɢɦɚɥɶɧɨ ɜɨɡɦɨɠɧɨɣ ɫɬɟɩɟɧɢ, ɧɨ ɞɟɣɫɬɜɢɬɟɥɶɧɨɫɬɶ ɬɚɤɨɜɚ, ɱɬɨ ɦɧɨɝɢɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ PHP ɧɟ ɧɪɚɜɢɬɫɹ ɢɧɬɟɪɮɟɣɫ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ ɢ ɨɧɢ ɫɬɚɥɤɢɜɚɸɬɫɹ ɫ ɡɚɬɪɭɞɧɟɧɢɹɦɢ ɩɪɢ ɩɨɩɵɬɤɟ ɜɢɡɭɚɥɶɧɨ ɩɪɟɞɫɬɚɜɢɬɶ ɫɜɨɢ ɫɬɪɭɤɬɭɪɢɪɨɜɚɧɧɵɟ ɞɚɧɧɵɟ, ɪɚɫɫɦɚɬɪɢɜɚɹ ɷɬɢ ɞɚɧɧɵɟ ɜ ɤɪɨɲɟɱɧɨɦ ɨɤɧɟ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ ɫ ɬɚɤɢɦɢ ɭɠɚɫɧɵɦɢ ɪɟɡɭɥɶɬɚɬɚɦɢ ɪɚɡɛɢɜɤɢ ɧɚ ɧɟɫɤɨɥɶɤɨ ɫɬɪɨɤ. Ʉɪɨɦɟ ɬɨɝɨ, ɧɟɤɨɬɨɪɵɟ Web-ɯɨɫɬɵ ɧɟ ɩɪɟɞɨɫɬɚɜɥɹɸɬ ɩɨɥɧɨɝɨ ɞɨɫɬɭɩɚ ɤ ɤɨɦɚɧɞɧɨɦɭ ɢɧɬɟɪɩɪɟɬɚɬɨɪɭ ɢ ɩɨɷɬɨɦɭ ɩɨɡɜɨɥɹɸɬ ɩɨɥɶɡɨɜɚɬɟɥɹɦ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɬɶ ɢ ɩɪɨɫɦɚɬɪɢɜɚɬɶ ɫɜɨɢ ɛɚɡɵ ɞɚɧɧɵɯ ɬɨɥɶɤɨ ɱɟɪɟɡ Web-ɢɧɬɟɪɮɟɣɫ. ȼ ɫɜɹɡɢ ɫ ɷɬɢɦ ɩɨɬɪɟɛɧɨɫɬɶ ɜ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɝɪɚɮɢɱɟɫɤɢɯ ɢɧɬɟɪɮɟɣɫɨɜ ɧɚ ɨɫɧɨɜɟ Web ɞɥɹ MySQL ɛɵɥɚ ɢ ɨɫɬɚɟɬɫɹ ɩɪɨɫɬɨ ɩɨɪɚɡɢɬɟɥɶɧɨɣ, ɧɟɫɦɨɬɪɹ ɧɚ ɬɨ, ɱɬɨ ɩɪɢ ɷɬɨɦ ɜɨɡɧɢɤɚɸɬ ɦɧɨɝɨɱɢɫɥɟɧɧɵɟ ɩɪɨɛɥɟɦɵ ɡɚɳɢɬɵ. ȿɫɥɢ ɜɵ ɫɨɛɢɪɚɟɬɟɫɶ ɩɪɢɦɟɧɹɬɶ ɨɞɧɭ ɢɡ ɬɚɤɢɯ ɤɥɢɟɧɬɫɤɢɯ ɩɪɨɝɪɚɦɦ (ɧɚɢɛɨɥɟɟ ɲɢɪɨɤɨ ɩɪɢɦɟɧɹɟɦɨɣ ɹɜɥɹɟɬɫɹ PHPMyAdmin, ɧɨ ɢɦɟɟɬɫɹ ɬɚɤɠɟ ɧɟɫɤɨɥɶɤɨ ɚɧɚɥɨɝɢɱɧɵɯ ɩɚɤɟɬɨɜ), ɬɨ ɞɨɥɠɧɵ ɩɨ ɦɟɧɶɲɟɣ ɦɟɪɟ ɡɧɚɬɶ, ɤɚɤ ɫɥɟɞɭɟɬ ɷɤɫɩɥɭɚɬɢɪɨɜɚɬɶ ɷɬɢ ɩɪɨɝɪɚɦɦɵ ɧɚɢɛɨɥɟɟ ɛɟɡɨɩɚɫɧɵɦ ɫɩɨɫɨɛɨɦ. Ɉɫɧɨɜɧɚɹ ɩɪɨɛɥɟɦɚ, ɫɜɹɡɚɧɧɚɹ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin, ɫɨɫɬɨɢɬ ɜ ɬɨɦ, ɱɬɨ ɷɤɫɩɥɭɚɬɚɰɢɹ ɷɬɨɣ ɩɪɨɝɪɚɦɦɵ ɧɟ ɩɨɡɜɨɥɹɟɬ ɥɭɱɲɟ ɩɨɧɹɬɶ ɩɪɨɛɥɟɦɵ ɡɚɳɢɬɵ MySQL ɢ ɤ ɬɨɦɭ ɠɟ ɫɬɚɧɨɜɢɬɫɹ ɩɪɢɱɢɧɨɣ ɜɨɡɧɢɤɧɨɜɟɧɢɹ ɧɟɤɨɬɨɪɵɯ ɞɨɩɨɥɧɢɬɟɥɶɧɵɯ ɧɚɪɭɲɟɧɢɣ ɡɚɳɢɬɵ. Ⱦɟɥɨ ɜ ɬɨɦ, ɱɬɨ ɧɟɨɛɯɨɞɢɦɨ ɨɛɟɫɩɟɱɢɬɶ ɧɚɞɥɟɠɚɳɭɸ ɩɨɞɞɟɪɠɤɭ ɧɟ ɬɨɥɶɤɨ ɫɢɫɬɟɦɵ ɩɪɚɜ ɞɨɫɬɭɩɚ MySQL, ɨɩɢɫɚɧɧɨɣ ɪɚɧɟɟ, ɧɨ ɢ ɫɨɡɞɚɬɶ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɭɪɨɜɟɧɶ ɡɚɳɢɬɵ Web. Ʉ ɫɨɠɚɥɟɧɢɸ, ɩɪɨɝɪɚɦɦɚ PHPMyAdmin ɧɟ ɩɨɡɜɨɥɹɟɬ ɥɟɝɤɨ ɞɨɛɢɬɶɫɹ ɤɚɱɟɫɬɜɟɧɧɨɣ ɡɚɳɢɬɵ Web. Ⱦɨɩɭɫɬɢɦ, ɱɬɨ ɭ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢɦɟɟɬɫɹ ɭɱɟɬɧɚɹ ɡɚɩɢɫɶ ɞɥɹ Web-ɯɨɫɬɢɧɝɚ ɫ ɞɨɫɬɭɩɨɦ ɤ ɤɨɦɚɧɞɧɨɦɭ ɢɧɬɟɪɩɪɟɬɚɬɨɪɭ ɨɞɧɨɝɨ ɢɡ ɤɨɦɩɶɸɬɟɪɨɜ, ɧɚɯɨɞɹɳɢɯɫɹ ɜ ɧɟɤɨɬɨɪɨɦ ɰɟɧɬɪɟ ɨɛɪɚɛɨɬɤɢ ɞɚɧɧɵɯ. ȿɫɥɢ ɫɟɬɶ ɷɤɫɩɥɭɚɬɢɪɭɟɬɫɹ ɞɨɥɠɧɵɦ ɨɛɪɚɡɨɦ, ɬɨ ɩɨɥɶɡɨɜɚɬɟɥɸ ɩɪɢɯɨɞɢɬɫɹ ɪɟɝɢɫɬɪɢɪɨɜɚɬɶɫɹ ɧɚ ɞɚɧɧɨɦ ɤɨɦɩɶɸɬɟɪɟ, ɩɨɞɤɥɸɱɚɹɫɶ ɱɟɪɟɡ ɡɚɲɢɮɪɨɜɚɧɧɨɟ ɫɨɟɞɢɧɟɧɢɟ, ɬɚɤɨɟ ɤɚɤ ssh. ɉɨɫɥɟ ɷɬɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɶ ɨɛɹɡɚɧ ɨɬɞɟɥɶɧɨ ɜɜɟɫɬɢ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢ ɩɚɪɨɥɶ ɛɚɡɵ ɞɚɧɧɵɯ, ɚ ɬɚɤɠɟ, ɜɨɡɦɨɠɧɨ, ɢɦɹ ɯɨɫɬɚ ɢ ɧɨɦɟɪ ɩɨɪɬɚ ɧɚ ɞɪɭɝɨɦ ɤɨɦɩɶɸɬɟɪɟ, ɱɬɨɛɵ ɩɨɞɤɥɸɱɢɬɶɫɹ ɤ ɫɟɪɜɟɪɭ ɛɚɡɵ ɞɚɧɧɵɯ MySQL, ɚ ɫɚɦ ɫɟɪɜɟɪ ɞɨɥɠɟɧ ɩɪɢɧɢɦɚɬɶ ɬɨɥɶɤɨ ɬɚɤɢɟ ɡɚɩɪɨɫɵ ɧɚ ɭɫɬɚɧɨɜɥɟɧɢɟ ɫɨɟɞɢɧɟɧɢɹ, ɤɨɬɨɪɵɟ ɢɫɯɨɞɹɬ ɨɬ ɬɨɝɨ ɤɨɧɤɪɟɬɧɨɝɨ ɤɨɦɩɶɸɬɟɪɚ, ɝɞɟ ɢɦɟɟɬɫɹ Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 359 ɭɱɟɬɧɚɹ ɡɚɩɢɫɶ ɩɨɥɶɡɨɜɚɬɟɥɹ. Ɍɚɤɚɹ ɫɢɫɬɟɦɚ ɧɟ ɹɜɥɹɟɬɫɹ ɢɞɟɚɥɶɧɨɣ (ɟɫɥɢ ɪɟɱɶ ɢɞɟɬ ɨ ɡɚɳɢɬɟ, ɬɨ ɢɞɟɚɥɶɧɵɯ ɫɢɫɬɟɦ ɧɟ ɫɭɳɟɫɬɜɭɟɬ), ɧɨ ɜɩɨɥɧɟ ɩɪɢɟɦɥɟɦɚ. ȼ ɨɬɥɢɱɢɟ ɨɬ ɷɬɨɝɨ, ɩɪɢ ɷɤɫɩɥɭɚɬɚɰɢɢ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin ɧɟ ɨɛɹɡɚɬɟɥɶɧɨ ɞɚɠɟ ɬɪɟɛɭɟɬɫɹ ɡɚɞɚɜɚɬɶ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢɥɢ ɩɚɪɨɥɶ. Ʉɚɠɞɵɣ, ɤɬɨ ɡɧɚɟɬ ɨ ɫɭɳɟɫɬɜɨɜɚɧɢɢ ɤɨɧɤɪɟɬɧɨɣ ɢɧɫɬɚɥɥɹɰɢɢ PHPMyAdmin, ɦɨɠɟɬ ɩɨɩɵɬɚɬɶɫɹ ɩɨɥɭɱɢɬɶ ɤ ɧɟɣ ɞɨɫɬɭɩ ɫ ɩɨɦɨɳɶɸ ɛɪɚɭɡɟɪɚ ɢɡ ɥɸɛɨɣ ɬɨɱɤɢ ɜ ɫɟɬɢ. ȿɫɥɢ ɠɟ ɢɫɩɨɥɶɡɭɟɬɫɹ ɤɨɧɮɢɝɭɪɚɰɢɹ, ɩɪɟɞɭɫɦɨɬɪɟɧɧɚɹ ɩɨ ɭɦɨɥɱɚɧɢɸ, ɬɨ ɩɨɬɟɧɰɢɚɥɶɧɵɣ ɧɚɪɭɲɢɬɟɥɶ ɩɪɢɨɛɪɟɬɚɟɬ ɜɫɟ ɩɪɚɜɚ ɜ ɫɢɫɬɟɦɟ, ɞɚɠɟ ɧɟ ɡɚɦɟɬɢɜ ɫɭɳɟɫɬɜɨɜɚɧɢɹ ɩɨɞɫɢɫɬɟɦɵ ɚɜɬɨɪɢɡɚɰɢɢ. Ȼɨɥɟɟ ɬɨɝɨ, ɟɫɥɢ ɜɵ ɧɟ ɜɨɡɶɦɟɬɟ ɧɚ ɫɟɛɹ ɨɛɹɡɚɧɧɨɫɬɢ ɩɨ ɜɵɩɨɥɧɟɧɢɸ ɬɚɤɨɣ ɧɚɫɬɪɨɣɤɢ ɤɨɧɮɢɝɭɪɚɰɢɢ Web-ɫɟɪɜɟɪɚ, ɱɬɨɛɵ ɨɧ ɩɪɢɧɢɦɚɥ ɬɨɥɶɤɨ ɡɚɩɪɨɫɵ ɧɚ ɭɫɬɚɧɨɜɥɟɧɢɟ ɫɨɟɞɢɧɟɧɢɹ ɩɨ ɩɪɨɬɨɤɨɥɭ HTTPS, ɬɨ ɫɨɟɞɢɧɟɧɢɟ ɦɟɠɞɭ ɛɪɚɭɡɟɪɨɦ ɢ Web-ɫɟɪɜɟɪɨɦ ɛɭɞɟɬ ɧɟɡɚɲɢɮɪɨɜɚɧɧɵɦ, ɩɨɷɬɨɦɭ ɜɫɟ ɞɚɧɧɵɟ ɛɭɞɭɬ ɩɟɪɟɞɚɜɚɬɶɫɹ ɜ ɩɪɹɦɨɦ ɢ ɨɛɪɚɬɧɨɦ ɧɚɩɪɚɜɥɟɧɢɹɯ ɱɟɪɟɡ ɨɛɵɱɧɨɟ ɫɨɟɞɢɧɟɧɢɟ HTTP. Ɍɚɤ ɤɚɤ ɠɟ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɭɞɨɛɧɵɦɢ ɫɪɟɞɫɬɜɚɦɢ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin, ɫɜɟɞɹ ɪɢɫɤ ɤ ɦɢɧɢɦɭɦɭ? ɉɪɟɠɞɟ ɜɫɟɝɨ, ɫɥɟɞɭɟɬ ɨɰɟɧɢɬɶ ɫɜɨɢ ɩɨɬɪɟɛɧɨɫɬɢ. Ɇɧɨɝɢɟ ɥɸɞɢ ɨɛɪɚɳɚɸɬɫɹ ɤ ɩɪɨɝɪɚɦɦɟ PHPMyAdmin ɬɨɥɶɤɨ ɜ ɨɱɟɧɶ ɪɟɞɤɢɯ ɫɥɭɱɚɹɯ, ɧɚɩɪɢɦɟɪ, ɞɥɹ ɩɟɪɜɨɧɚɱɚɥɶɧɨɣ ɧɚɫɬɪɨɣɤɢ ɫɯɟɦɵ ɛɚɡɵ ɞɚɧɧɵɯ. ȿɫɥɢ ɜɚɲɢ ɩɨɬɪɟɛɧɨɫɬɢ ɫɨɫɬɨɹɬ ɢɦɟɧɧɨ ɜ ɷɬɨɦ, ɬɨ ɞɥɹ ɜɚɫ ɜɨɨɛɳɟ ɧɟɬ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɢɧɫɬɚɥɥɢɪɨɜɚɬɶ ɩɪɨɝɪɚɦɦɭ PHPMyAdmin ɧɚ ɩɪɨɢɡɜɨɞɫɬɜɟɧɧɨɦ ɫɟɪɜɟɪɟ. ɍɫɬɚɧɨɜɢɬɟ ɛɚɡɭ ɞɚɧɧɵɯ ɥɨɤɚɥɶɧɨ, ɜɵɩɨɥɧɢɬɟ ɧɚɫɬɪɨɣɤɭ ɫɯɟɦɵ ɛɚɡɵ ɞɚɧɧɵɯ ɜ ɩɨɥɧɨɦ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɜɚɲɢɦɢ ɩɨɬɪɟɛɧɨɫɬɹɦɢ, ɚ ɡɚɬɟɦ ɫɨɡɞɚɣɬɟ ɤɨɩɢɸ ɨɩɪɟɞɟɥɟɧɢɹ ɥɨɤɚɥɶɧɨɣ ɛɚɡɵ ɞɚɧɧɵɯ ɜ ɜɢɞɟ ɤɨɞɚ SQL, ɤɨɬɨɪɵɣ ɦɨɠɟɬ ɛɵɬɶ ɩɪɢɦɟɧɟɧ ɧɚ ɩɪɨɢɡɜɨɞɫɬɜɟɧɧɨɦ ɫɟɪɜɟɪɟ. ɗɬɨ — ɨɱɟɧɶ ɥɟɝɤɢɣ ɫɩɨɫɨɛ, ɤɨɬɨɪɵɣ ɹɜɥɹɟɬɫɹ ɧɚɦɧɨɝɨ ɛɨɥɟɟ ɛɟɡɨɩɚɫɧɵɦ ɢ ɫɜɨɞɢɬ ɤ ɦɢɧɢɦɭɦɭ ɜɪɟɦɹ ɩɪɨɫɬɨɹ ɩɪɨɢɡɜɨɞɫɬɜɟɧɧɵɯ ɫɟɪɜɟɪɨɜ. Ⱦɥɹ ɩɨɥɭɱɟɧɢɹ ɞɨɩɨɥɧɢɬɟɥɶɧɨɣ ɢɧɮɨɪɦɚɰɢɢ ɨ ɫɨɡɞɚɧɢɢ ɤɨɩɢɣ ɫɬɪɭɤɬɭɪɵ ɢ ɞɚɧɧɵɯ ɛɚɡɵ ɞɚɧɧɵɯ ɫ ɩɨɦɨɳɶɸ ɩɪɨɝɪɚɦɦɵ mysqldump ɨɛɪɚɬɢɬɟɫɶ ɤ ɪɚɡɞɟɥɭ “ɋɨɡɞɚɧɢɟ ɪɟɡɟɪɜɧɵɯ ɤɨɩɢɣ” ɧɢɠɟ ɜ ɷɬɨɣ ɝɥɚɜɟ. ȿɞɢɧɫɬɜɟɧɧɵɦ ɧɟɞɨɫɬɚɬɤɨɦ ɪɚɫɫɦɚɬɪɢɜɚɟɦɨɝɨ ɦɟɬɨɞɚ ɹɜɥɹɟɬɫɹ ɬɨ, ɱɬɨ ɡɚɞɚɱɚ ɜɧɟɫɟɧɢɹ ɜɪɟɦɹ ɨɬ ɜɪɟɦɟɧɢ ɧɟɛɨɥɶɲɢɯ ɢɡɦɟɧɟɧɢɣ ɜ ɫɯɟɦɭ ɛɚɡɵ ɞɚɧɧɵɯ, ɤɨɬɨɪɚɹ ɭɠɟ ɫɨɞɟɪɠɢɬ ɞɚɧɧɵɟ, ɫɬɚɧɨɜɢɬɫɹ ɜɟɫɶɦɚ ɫɥɨɠɧɨɣ. Ɉɞɧɚɤɨ ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɦɨɠɧɨ ɩɪɟɞɭɫɦɨɬɪɟɬɶ ɩɪɢɦɟɧɟɧɢɟ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin, ɧɨ ɡɚɩɪɟɬɢɬɶ ɞɨɫɬɭɩ ɤ ɧɟɣ ɧɚ ɬɨɬ ɩɟɪɢɨɞ, ɤɨɝɞɚ ɨɧɚ ɧɟ ɢɫɩɨɥɶɡɭɟɬɫɹ. Ⱦɥɹ ɷɬɨɝɨ ɦɨɠɧɨ ɩɪɨɫɬɨ ɡɚɞɚɬɶ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɤ ɤɚɬɚɥɨɝɭ, ɝɞɟ ɧɚɯɨɞɢɬɫɹ ɩɪɨɝɪɚɦɦɚ PHPMyAdmin, ɢ ɤ ɮɚɣɥɚɦ ɜ ɷɬɨɦ ɤɚɬɚɥɨɝɟ ɬɚɤɢɦ ɨɛɪɚɡɨɦ, ɱɬɨɛɵ ɛɵɥɢ ɡɚɩɪɟɳɟɧɵ ɡɚɩɪɨɫɵ ɧɚ ɩɨɞɤɥɸɱɟɧɢɟ, ɩɨɫɬɭɩɚɸɳɢɟ ɨɬ ɩɨɥɶɡɨɜɚɬɟɥɹ, ɩɨɞ ɢɦɟɧɟɦ ɤɨɬɨɪɨɝɨ ɪɚɛɨɬɚɟɬ Web-ɫɟɪɜɟɪ (ɬ.ɟ. ɨɬ ɩɨɥɶɡɨɜɚɬɟɥɹ nobody). Ⱥ ɜ ɫɥɟɞɭɸɳɢɣ ɪɚɡ, ɤɨɝɞɚ ɩɨɬɪɟɛɭɟɬɫɹ ɩɪɢɛɟɝɧɭɬɶ ɤ ɢɫɩɨɥɶɡɨɜɚɧɢɸ PHPMyAdmin, ɞɨɫɬɚɬɨɱɧɨ ɛɭɞɟɬ ɩɪɨɫɬɨ ɡɚ ɨɞɧɭ ɫɟɤɭɧɞɭ ɩɟɪɟɨɩɪɟɞɟɥɢɬɶ ɩɪɚɜɚ ɞɨɫɬɭɩɚ, ɞɥɹ ɬɨɝɨ ɱɬɨɛɵ ɩɨɥɶɡɨɜɚɬɟɥɶ, ɨɥɢɰɟɬɜɨɪɹɸɳɢɣ ɩɪɨɝɪɚɦɦɭ Web-ɫɟɪɜɟɪɚ, ɫɧɨɜɚ ɦɨɝ ɱɢɬɚɬɶ ɷɬɢ ɮɚɣɥɵ. Ɍɟɦ ɧɟ ɦɟɧɟɟ ɧɚ ɬɨ ɜɪɟɦɹ, ɤɨɝɞɚ ɪɚɡɪɟɲɟɧ ɞɨɫɬɭɩ ɤ Web-ɤɥɢɟɧɬɭ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin, ɠɟɥɚɬɟɥɶɧɨ ɬɚɤɠɟ ɩɪɢɦɟɧɹɬɶ ɚɭɬɟɧɬɢɮɢɤɚɰɢɸ ɫ ɩɨɦɨɳɶɸ ɩɪɨɬɨɤɨɥɚ http ɢɥɢ cookie-ɮɚɣɥɨɜ. ȿɳɟ ɨɞɧɚ ɦɟɪɚ ɡɚɳɢɬɵ ɦɨɠɟɬ ɩɪɟɞɭɫɦɚɬɪɢɜɚɬɶ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɲɢɮɪɨɜɚɧɢɹ SSL ɜ ɤɚɬɚɥɨɝɟ PHPMyAdmin. Ɍɚɤɨɣ ɫɩɨɫɨɛ ɨɪɝɚɧɢɡɚɰɢɢ ɡɚɳɢɬɵ ɦɨɠɟɬ ɫɬɚɬɶ ɪɟɲɟɧɢɟɦ ɩɪɨɛɥɟɦɵ, ɫɜɹɡɚɧɧɨɣ ɫ ɩɟɪɟɞɚɱɟɣ ɧɟɡɚɲɢɮɪɨɜɚɧɧɵɯ ɤɨɧɮɢɞɟɧɰɢɚɥɶɧɵɯ ɞɚɧɧɵɯ ɦɟɠɞɭ Web-ɫɟɪɜɟɪɨɦ ɢ ɛɪɚɭɡɟɪɨɦ. Ⱦɨɩɨɥɧɢɬɟɥɶɧɚɹ ɢɧɮɨɪɦɚɰɢɹ ɩɨ ɷɬɨɣ ɬɟɦɟ ɩɪɢɜɟɞɟɧɚ ɧɚ ɭɤɚɡɚɧɧɵɯ ɧɢɠɟ Web-ɭɡɥɚɯ. www.modssl.org (ɞɟɦɨɧ httpd ɫɟɪɜɟɪɚ Apache). www.microsoft.com/technet/treeview/default.asp?url=/technet/ prodtechnol/windowsserver2003/proddocs/deployguide/iisdg_mea_ nfmd.asp (ɫɟɪɜɟɪ IIS 6). ɇɚɢɛɨɥɟɟ ɲɢɪɨɤɨ ɩɪɢɦɟɧɹɟɦɵɣ ɦɟɬɨɞ ɩɨɜɵɲɟɧɢɹ ɭɪɨɜɧɹ ɡɚɳɢɬɵ ɫɨɫɬɨɢɬ ɜ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɫɯɟɦ ɚɭɬɟɧɬɢɮɢɤɚɰɢɢ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin ɫ ɩɨɦɨɳɶɸ ɩɪɨɬɨɤɨɥɚ http ɢɥɢ cookie-ɮɚɣɥɨɜ. Ⱦɥɹ ɷɬɨɝɨ ɬɪɟɛɭɟɬɫɹ ɫɨɡɞɚɧɢɟ ɫɩɟɰɢɚɥɶɧɨɣ ɭɱɟɬɧɨɣ ɡɚɩɢɫɢ ɩɨɥɶɡɨɜɚɬɟɥɹ PHPMyAdmin, ɫ ɩɨɦɨɳɶɸ ɤɨɬɨɪɨɣ ɦɨɠɟɬ ɨɫɭɳɟɫɬɜɥɹɬɶɫɹ ɱɬɟɧɢɟ ɬɚɛɥɢɰ ɩɪɚɜ ɞɨɫɬɭɩɚ 360 ×àñòü II. PHP è MySQL MySQL, ɧɚɪɹɞɭ ɫ ɨɛɵɱɧɨɣ ɭɱɟɬɧɨɣ ɡɚɩɢɫɶɸ ɚɞɦɢɧɢɫɬɪɚɬɨɪɚ ɛɚɡɵ ɞɚɧɧɵɯ. Ɇɟɬɨɞ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɩɪɨɬɨɤɨɥɚ http ɦɨɠɟɬ ɩɪɢɦɟɧɹɬɶɫɹ ɬɨɥɶɤɨ ɩɪɢ ɪɚɛɨɬɟ ɫ ɫɟɪɜɟɪɨɦ Apache. Ɇɟɬɨɞ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ cookie-ɮɚɣɥɨɜ ɩɪɟɞɭɫɦɚɬɪɢɜɚɟɬ ɲɢɮɪɨɜɚɧɢɟ ɩɚɪɨɥɟɣ ɩɟɪɟɞ ɢɯ ɡɚɩɢɫɶɸ ɜ cookie-ɮɚɣɥɵ. ɗɬɨɬ ɦɟɬɨɞ ɦɨɠɟɬ ɩɪɢɦɟɧɹɬɶɫɹ ɧɚ Web-ɫɟɪɜɟɪɚɯ, ɨɬɥɢɱɧɵɯ ɨɬ Apache, ɢ ɹɜɥɹɟɬɫɹ ɟɞɢɧɫɬɜɟɧɧɵɦ ɦɟɬɨɞɨɦ, ɤɨɬɨɪɵɣ ɨɛɟɫɩɟɱɢɜɚɟɬ ɩɨɥɧɵɣ ɜɵɯɨɞ ɢɡ ɫɢɫɬɟɦɵ. Ⱦɥɹ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɚɜɬɨɪɢɡɚɰɢɢ ɫ ɩɨɦɨɳɶɸ ɩɪɨɬɨɤɨɥɚ http ɢɥɢ cookie-ɮɚɣɥɨɜ ɫɨɡɞɚɣɬɟ ɭɱɟɬɧɭɸ ɡɚɩɢɫɶ ɩɨɥɶɡɨɜɚɬɟɥɹ PHPMyAdmin, ɤɚɤ ɩɨɤɚɡɚɧɨ ɧɢɠɟ (ɩɨɫɥɟ ɪɚɡɚɪɯɢɜɢɪɨɜɚɧɢɹ ɢɥɢ ɪɚɫɩɚɤɨɜɤɢ ɩɚɤɟɬɚ PHPMyAdmin ɜ ɤɨɪɧɟɜɨɦ ɤɚɬɚɥɨɝɟ ɞɨɤɭɦɟɧɬɨɜ Web-ɫɟɪɜɟɪɚ). GRANT USAGE ON mysql.* TO 'pmauser'@'localhost' IDENTIFIED BY 'pmapassword'; GRANT SELECT ( Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv ) ON mysql.user TO 'pmauser'@'localhost'; GRANT SELECT ON mysql.db TO 'pmauser'@'localhost'; GRANT SELECT ON mysql.host TO 'pmauser'@'localhost'; GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO 'pmauser'@'localhost'; ɉɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɨɛɟɢɯ ɫɯɟɦ ɚɜɬɨɪɢɡɚɰɢɢ ɧɟɨɛɯɨɞɢɦɨ ɬɚɤɠɟ ɡɚɞɚɬɶ ɡɧɚɱɟɧɢɹ ɫɥɟɞɭɸɳɢɯ ɩɨɥɟɣ ɜ ɮɚɣɥɟ config.inc.php ɩɪɨɝɪɚɦɦɵ PHPMyAdmin: $cfg['PmaAbsoluteUri'] = 'http://localhost/phpMyAdmin'; $cfg['Servers'][$i]['host'] = 'localhost'; $cfg['Servers'][$i]['auth_type'] = 'http or cookie'; $cfg['Servers'][$i]['user'] = 'pmauser'; ɉɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɚɜɬɨɪɢɡɚɰɢɢ ɧɚ ɨɫɧɨɜɟ cookie-ɮɚɣɥɨɜ ɧɟɨɛɯɨɞɢɦɨ ɬɚɤɠɟ ɡɚɞɚɬɶ ɡɧɚɱɟɧɢɟ ɫɥɟɞɭɸɳɟɝɨ ɩɨɥɹ: $cfg['blowfish_secret'] = 'Supersecret passphrase'; Ɍɟɩɟɪɶ ɩɪɢ ɩɨɩɵɬɤɟ ɩɨɞɤɥɸɱɟɧɢɹ ɩɨɹɜɥɹɟɬɫɹ ɥɢɛɨ ɨɫɧɨɜɧɨɟ ɜɫɩɥɵɜɚɸɳɟɟ ɨɤɧɨ ɚɜɬɨɪɢɡɚɰɢɢ Apache, ɥɢɛɨ Web-ɮɨɪɦɚ. ȼɜɟɞɢɬɟ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢ ɩɚɪɨɥɶ ɚɞɦɢɧɢɫɬɪɚɬɨɪɚ ɛɚɡɵ ɞɚɧɧɵɯ (ɧɟ ɢɫɩɨɥɶɡɭɣɬɟ ɭɱɟɬɧɭɸ ɡɚɩɢɫɶ ɩɨɥɶɡɨɜɚɬɟɥɹ ɛɚɡɵ ɞɚɧɧɵɯ root!), ɢ ɜɚɦ ɛɭɞɭɬ ɩɪɟɞɨɫɬɚɜɥɟɧɵ ɬɨɱɧɨ ɬɚɤɢɟ ɠɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ MySQL, ɤɚɤ ɢ ɩɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɤɥɢɟɧɬɫɤɨɣ ɩɪɨɝɪɚɦɦɵ MySQL ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ. ɇɚɤɨɧɟɰ, ɩɪɟɞɭɫɦɨɬɪɟɧ ɟɳɟ ɨɞɢɧ ɫɨɦɧɢɬɟɥɶɧɵɣ ɦɟɬɨɞ “ɚɭɬɟɧɬɢɮɢɤɚɰɢɢ” PHPMyAdmin, ɤɨɬɨɪɵɣ ɨɛɵɱɧɨ ɧɟ ɫɥɟɞɭɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶ, — ɬɚɤ ɧɚɡɵɜɚɟɦɵɣ ɦɟɬɨɞ ɫ ɩɪɢɦɟɧɟɧɢɟɦ ɮɚɣɥɚ config. ɗɬɨɬ ɦɟɬɨɞ ɡɚɤɥɸɱɚɟɬɫɹ ɜ ɬɨɦ, ɱɬɨ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢ ɩɚɪɨɥɶ ɚɞɦɢɧɢɫɬɪɚɬɨɪɚ ɛɚɡɵ ɞɚɧɧɵɯ ɜɜɨɞɹɬɫɹ ɜ ɮɚɣɥ config.inc.php. ɉɨɫɥɟ ɷɬɨɝɨ ɜɨɡɦɨɠɧɨɫɬɶ ɩɪɨɫɦɚɬɪɢɜɚɬɶ ɛɚɡɭ ɞɚɧɧɵɯ ɩɨɥɭɱɚɟɬ ɥɸɛɨɣ, ɜ ɱɶɟɦ ɪɚɫɩɨɪɹɠɟɧɢɢ ɢɦɟɟɬɫɹ ɛɪɚɭɡɟɪ. ȿɞɢɧɫɬɜɟɧɧɵɦɢ ɨɛɫɬɨɹɬɟɥɶɫɬɜɚɦɢ, ɜ ɤɨɬɨɪɵɯ ɦɨɠɧɨ ɛɵɥɨ ɛɵ ɪɚɫɫɦɚɬɪɢɜɚɬɶ ɜɨɡɦɨɠɧɨɫɬɶ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɞɚɧɧɨɝɨ ɦɟɬɨɞɚ, ɹɜɥɹɟɬɫɹ ɥɨɤɚɥɶɧɵɣ ɤɨɦɩɶɸɬɟɪ, ɤɨɬɨɪɵɣ ɧɟ ɩɪɢɧɢɦɚɟɬ ɡɚɩɪɨɫɵ ɧɚ ɭɫɬɚɧɨɜɥɟɧɢɟ ɫɨɟɞɢɧɟɧɢɣ ɩɨ ɩɪɨɬɨɤɨɥɭ HTTP ɢɡ ɜɧɟɲɧɟɝɨ ɦɢɪɚ. ɋɥɟɞɭɟɬ ɨɬɦɟɬɢɬɶ, ɱɬɨ ɩɨɫɥɟ ɭɫɬɚɧɨɜɤɢ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin ɦɨɠɧɨ ɥɟɝɤɨ ɩɨɥɭɱɢɬɶ ɞɨɫɬɭɩ ɤ ɨɛɲɢɪɧɨɣ ɢɧɮɨɪɦɚɰɢɢ ɨ ɛɚɡɚɯ ɞɚɧɧɵɯ MySQL. ȼɵɛɪɚɜ ɛɚɡɭ ɞɚɧɧɵɯ ɢɡ ɫɩɢɫɤɚ ɞɨɫɬɭɩɧɵɯ ɛɚɡ ɞɚɧɧɵɯ, ɜɵ ɭɜɢɞɢɬɟ ɝɥɚɜɧɵɣ ɷɤɪɚɧ ɛɚɡɵ ɞɚɧɧɵɯ, ɧɚɩɨɞɨɛɢɟ ɩɪɢɜɟɞɟɧɧɨɝɨ ɧɚ ɪɢɫ. 14.1. ɉɨɥɶɡɨɜɚɬɟɥɢ ɝɪɚɮɢɱɟɫɤɨɝɨ ɢɧɬɟɪɮɟɣɫɚ, ɩɨ-ɜɢɞɢɦɨɦɭ, ɧɟ ɫɬɨɥɤɧɭɬɫɹ ɫ ɤɚɤɢɦɢ-ɥɢɛɨ ɫɥɨɠɧɨɫɬɹɦɢ ɩɪɢ ɩɟɪɟɦɟɳɟɧɢɢ ɩɨ ɢɧɬɟɪɮɟɣɫɭ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin, ɧɚɱɢɧɚɹ ɫ ɷɬɨɝɨ Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 361 ɷɤɪɚɧɚ. ɇɨ, ɤ ɫɨɠɚɥɟɧɢɸ, ɜ ɩɪɨɝɪɚɦɦɟ PHPMyAdmin ɢɫɩɨɥɶɡɭɟɬɫɹ ɧɟɦɧɨɝɨ ɧɟ ɬɚɤɚɹ ɬɟɪɦɢɧɨɥɨɝɢɹ ɞɥɹ ɨɛɨɡɧɚɱɟɧɢɹ ɨɩɟɪɚɰɢɣ, ɤɚɤ ɜ ɤɥɢɟɧɬɫɤɨɣ ɩɪɨɝɪɚɦɦɟ MySQL: “structure”, ɚ ɧɟ “show columns”; “browse”, ɚ ɧɟ “select”; “export”, ɚ ɧɟ “dump”, ɧɨ ɩɨɫɥɟ ɩɪɢɨɛɪɟɬɟɧɢɹ ɧɟɛɨɥɶɲɨɝɨ ɨɩɵɬɚ ɪɚɛɨɬɵ ɫ ɷɬɨɣ ɩɪɨɝɪɚɦɦɨɣ ɜɫɟ ɧɚɦɧɨɝɨ ɭɩɪɨɳɚɟɬɫɹ. Ɋɢɫ. 14.1. Ƚɥɚɜɧɵɣ ɷɤɪɚɧ ɛɚɡɵ ɞɚɧɧɵɯ ɜ ɩɪɨɝɪɚɦɦɟ PHPMyAdmin Внимание! Ɉɩɪɟɞɟɥɟɧɧɵɟ ɫɥɨɠɧɨɫɬɢ ɜ ɪɚɛɨɬɟ ɫ ɩɪɨɝɪɚɦɦɨɣ PHPMyAdmin ɜɨɡɧɢɤɚɸɬ ɭ ɥɸɞɟɣ ɫ ɧɚɪɭɲɟɧɢɟɦ ɰɜɟɬɨɜɨɝɨ ɡɪɟɧɢɹ, ɩɨɫɤɨɥɶɤɭ ɜɫɟ ɨɩɚɫɧɵɟ ɨɩɟɪɚɰɢɢ ɨɛɨɡɧɚɱɟɧɵ ɫ ɩɨɦɨɳɶɸ ɩɢɤɬɨɝɪɚɦɦ ɢɥɢ ɫɫɵɥɨɤ ɤɪɚɫɧɨɝɨ ɰɜɟɬɚ. Ʉ ɫɱɚɫɬɶɸ, ɩɪɟɠɞɟ ɱɟɦ ɛɭɞɟɬ ɜɵɩɨɥɧɟɧɚ ɥɸɛɚɹ ɨɩɟɪɚɰɢɹ ɭɧɢɱɬɨɠɟɧɢɹ ɢɥɢ ɦɚɫɫɨɜɨɝɨ ɭɞɚɥɟɧɢɹ, ɩɨɹɜɥɹɟɬɫɹ ɡɚɩɪɨɫ ɧɚ ɩɨɞɬɜɟɪɠɞɟɧɢɟ, ɩɨɷɬɨɦɭ ɜɟɪɨɹɬɧɨɫɬɶ ɜɨɡɧɢɤɧɨɜɟɧɢɹ ɧɟɭɦɵɲɥɟɧɧɵɯ ɨɲɢɛɨɤ ɫɜɨɞɢɬɫɹ ɤ ɦɢɧɢɦɭɦɭ, ɩɪɢ ɭɫɥɨɜɢɢ, ɱɬɨ ɩɨɥɶɡɨɜɚɬɟɥɶ ɧɟ ɧɚɠɢɦɚɟɬ ɤɥɚɜɢɲɭ <Enter> ɛɟɡ ɪɚɡɛɨɪɚ. Ñîçäàíèå ðåçåðâíûõ êîïèé Ɋɟɡɟɪɜɧɵɟ ɤɨɩɢɢ ɛɚɡ ɞɚɧɧɵɯ ɦɨɠɧɨ ɫɨɡɞɚɜɚɬɶ ɞɜɭɦɹ ɫɩɨɫɨɛɚɦɢ: ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɤɨɩɢɪɭɹ ɤɚɬɚɥɨɝ ɫ ɞɚɧɧɵɦɢ (ɥɢɛɨ ɜɪɭɱɧɭɸ, ɥɢɛɨ ɫ ɩɨɦɨɳɶɸ ɫɰɟɧɚɪɢɹ mysqlhotcopy ɜ ɫɢɫɬɟɦɟ Unix) ɢɥɢ ɢɫɩɨɥɶɡɭɹ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɟ ɫɪɟɞɫɬɜɨ mysqldump ɞɥɹ ɜɵɜɨɞɚ ɢɧɮɨɪɦɚɰɢɢ ɜ ɮɚɣɥ ɫ ɤɨɦɚɧɞɚɦɢ SQL, ɤɨɬɨɪɵɣ ɫɨɞɟɪɠɢɬ ɤɨɩɢɸ ɛɚɡɵ ɞɚɧɧɵɯ. ɉɟɪɜɵɣ ɫɩɨɫɨɛ ɧɟɦɧɨɝɨ ɛɵɫɬɪɟɟ, ɧɨ ɩɨɫɥɟɞɧɢɣ ɩɪɟɞɨɫɬɚɜɥɹɟɬ ɛɨɥɶɲɟ ɜɨɡɦɨɠɧɨɫɬɟɣ. ɋ ɩɨɦɨɳɶɸ ɭɬɢɥɢɬɵ mysqldump ɦɨɠɧɨ ɜɵɛɪɚɬɶ ɜɚɪɢɚɧɬ ɤɨɩɢɪɨɜɚɧɢɹ ɬɨɥɶɤɨ ɫɬɪɭɤɬɭɪɵ ɛɚɡɵ ɞɚɧɧɵɯ, ɬɨɥɶɤɨ ɞɚɧɧɵɯ ɢɥɢ ɬɨɝɨ ɢ ɞɪɭɝɨɝɨ. ɇɢɠɟ ɩɪɢɜɟɞɟɧ ɫɚɦɵɣ ɩɪɨɫɬɨɣ ɩɪɢɦɟɪ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɭɬɢɥɢɬɵ mysqldump. mysqldump -u username -p databasename > dumpfilename.sql ɗɬɚ ɤɨɦɚɧɞɚ ɜɵɜɨɞɢɬ ɬɟɤɫɬɨɜɵɣ ɮɚɣɥ, ɤɨɬɨɪɵɣ ɦɨɠɟɬ ɛɵɬɶ ɫɱɢɬɚɧ ɧɚ ɞɪɭɝɨɦ ɫɟɪɜɟɪɟ ɛɚɡɵ ɞɚɧɧɵɯ, ɩɪɢɦɟɪɧɨ ɬɚɤɢɦ ɨɛɪɚɡɨɦ: 362 ×àñòü II. PHP è MySQL mysql -u root -p databasename < dumpfilename.sql ȼɦɟɫɬɨ ɡɚɩɢɫɢ ɜɵɜɨɞɚ ɭɬɢɥɢɬɵ mysqldump ɜ ɮɚɣɥ ɩɨɥɭɱɟɧɧɵɟ ɜɵɯɨɞɧɵɟ ɞɚɧɧɵɟ ɦɨɠɧɨ ɬɚɤɠɟ ɧɚɩɪɚɜɢɬɶ ɩɨ ɤɚɧɚɥɭ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɧɚ ɞɪɭɝɨɣ ɫɟɪɜɟɪ, ɤɚɤ ɩɨɤɚɡɚɧɨ ɧɢɠɟ. mysqldump -u username -p databasename | mysql -h remote-host -u remoteuser -p -C databasename Ɍɟɦ ɧɟ ɦɟɧɟɟ ɜ ɧɟɤɨɬɨɪɵɯ ɫɥɭɱɚɹɯ ɬɚɤɨɣ ɜɚɪɢɚɧɬ ɜɵɜɨɞɚ ɢ ɜɜɨɞɚ ɞɚɧɧɵɯ ɦɨɠɟɬ ɨɤɚɡɚɬɶɫɹ ɦɟɧɟɟ ɛɟɡɨɩɚɫɧɵɦ, ɩɨɫɤɨɥɶɤɭ ɬɪɟɛɭɟɬ ɩɟɪɟɞɚɱɢ ɭɞɚɥɟɧɧɨɦɭ ɯɨɫɬɭ ɤɨɦɚɧɞɵ ɩɪɢɧɢɦɚɬɶ ɡɚɩɪɨɫɵ ɧɚ ɭɫɬɚɧɨɜɥɟɧɢɟ ɫɨɟɞɢɧɟɧɢɣ, ɜ ɤɨɬɨɪɵɯ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɦɨɞɢɮɢɤɚɰɢɹ ɛɚɡɵ ɞɚɧɧɵɯ, ɨɬ ɜɧɟɲɧɢɯ ɤɥɢɟɧɬɫɤɢɯ ɩɪɨɝɪɚɦɦ. ɉɪɢɜɟɞɟɧɧɚɹ ɜɵɲɟ ɨɫɧɨɜɧɚɹ ɤɨɦɚɧɞɚ ɜɩɨɥɧɟ ɨɩɪɚɜɞɵɜɚɟɬ ɫɜɨɟ ɧɚɡɧɚɱɟɧɢɟ. ɉɨɞ ɷɬɢɦ ɩɨɞɪɚɡɭɦɟɜɚɟɬɫɹ, ɱɬɨ ɜɵɩɨɥɧɟɧɢɟ ɭɤɚɡɚɧɧɨɣ ɤɨɦɚɧɞɵ ɩɪɢɜɨɞɢɬ ɤ ɩɨɥɭɱɟɧɢɸ ɚɤɤɭɪɚɬɧɨɝɨ ɮɚɣɥɚ ɫ ɤɨɦɚɧɞɚɦɢ SQL, ɤɨɬɨɪɵɣ ɫɨɞɟɪɠɢɬ ɧɟ ɬɨɥɶɤɨ ɢɧɮɨɪɦɚɰɢɸ ɨ ɫɬɪɭɤɬɭɪɟ, ɧɨ ɢ ɞɚɧɧɵɟ, ɩɨɥɭɱɟɧɧɵɟ ɢɡ ɪɚɫɫɦɚɬɪɢɜɚɟɦɨɣ ɛɚɡɵ ɞɚɧɧɵɯ. ɇɨ ɢɧɨɝɞɚ ɬɪɟɛɭɟɬɫɹ ɞɨɩɨɥɧɢɬɟɥɶɧɨ ɤɨɧɤɪɟɬɢɡɢɪɨɜɚɬɶ ɪɟɡɭɥɶɬɚɬɵ, ɩɪɟɞɨɫɬɚɜɥɹɟɦɵɟ ɭɬɢɥɢɬɨɣ mysqldump, ɜ ɫɜɹɡɢ ɫ ɬɟɦ, ɱɬɨ ɞɨɥɠɧɚ ɛɵɬɶ ɩɨɥɭɱɟɧɚ ɬɨɥɶɤɨ ɢɧɮɨɪɦɚɰɢɹ ɨ ɫɬɪɭɤɬɭɪɟ ɢɥɢ ɬɨɥɶɤɨ ɞɚɧɧɵɟ. Ⱦɪɭɝɢɟ ɨɩɰɢɢ ɩɨɡɜɨɥɹɸɬ ɩɨɥɭɱɢɬɶ ɫɨɞɟɪɠɢɦɨɟ ɜɫɟɯ ɛɚɡ ɞɚɧɧɵɯ ɧɚ ɭɤɚɡɚɧɧɨɦ ɫɟɪɜɟɪɟ ɢɥɢ ɬɨɥɶɤɨ ɧɟɤɨɬɨɪɵɯ ɬɚɛɥɢɰ ɢɡ ɜɵɛɪɚɧɧɨɣ ɛɚɡɵ ɞɚɧɧɵɯ. ɋɟɪɜɟɪ MySQL ɩɨɡɜɨɥɹɟɬ, ɫ ɨɞɧɨɣ ɫɬɨɪɨɧɵ, ɡɚɞɚɜɚɬɶ ɪɚɡɥɢɱɧɵɟ ɤɨɦɛɢɧɚɰɢɢ ɛɚɡ ɞɚɧɧɵɯ ɢ (ɢɥɢ) ɬɚɛɥɢɰ, ɚ ɫ ɞɪɭɝɨɣ — ɭɤɚɡɵɜɚɬɶ ɡɧɚɱɟɧɢɹ ɜɫɟɜɨɡɦɨɠɧɵɯ ɨɩɰɢɣ ɜ ɤɨɦɚɧɞɟ ɤɨɩɢɪɨɜɚɧɢɹ. ȿɫɥɢ ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɤɨɩɢɢ ɧɟɨɛɯɨɞɢɦɨ ɜɵɛɪɚɬɶ ɨɩɪɟɞɟɥɟɧɧɵɟ ɬɚɛɥɢɰɵ ɢɡ ɭɤɚɡɚɧɧɨɣ ɛɚɡɵ ɞɚɧɧɵɯ, ɞɨɫɬɚɬɨɱɧɨ ɩɟɪɟɱɢɫɥɢɬɶ ɢɦɟɧɚ ɷɬɢɯ ɬɚɛɥɢɰ ɩɨɫɥɟ ɢɦɟɧɢ ɛɚɡɵ ɞɚɧɧɵɯ: mysqldump -u username -p databasename table1 table2 > dumpfilename.sql ȿɫɥɢ ɠɟ ɬɪɟɛɭɟɬɫɹ ɩɨɥɭɱɢɬɶ ɤɨɩɢɸ ɥɢɲɶ ɧɟɤɨɬɨɪɵɯ ɛɚɡ ɞɚɧɧɵɯ, ɪɚɛɨɬɚɸɳɢɯ ɩɨɞ ɭɩɪɚɜɥɟɧɢɟɦ ɤɨɧɤɪɟɬɧɨɝɨ ɫɟɪɜɟɪɚ, ɬɨ ɦɨɠɧɨ ɜɜɟɫɬɢ ɨɩɰɢɸ --databases, ɚ ɡɚɬɟɦ ɡɚɞɚɬɶ ɫɩɢɫɨɤ ɛɚɡ ɞɚɧɧɵɯ, ɤɚɤ ɩɨɤɚɡɚɧɨ ɧɢɠɟ. ɇɨ ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɨɬɫɭɬɫɬɜɭɟɬ ɜɨɡɦɨɠɧɨɫɬɶ ɭɤɚɡɵɜɚɬɶ ɨɬɞɟɥɶɧɵɟ ɬɚɛɥɢɰɵ. mysqldump -u username -p --databases database1 database2 > dumpfilename.sql ȿɫɥɢ ɧɟɨɛɯɨɞɢɦɨ ɩɨɥɭɱɢɬɶ ɤɨɩɢɸ ɜɫɟɯ ɛɚɡ ɞɚɧɧɵɯ, ɬɨ ɫɥɟɞɭɟɬ ɜɜɟɫɬɢ ɨɩɰɢɸ --alldatabases: mysqldump -u username -p --all-databases > dumpfilename.sql Ʌɸɛɭɸ ɢɡ ɨɩɢɫɚɧɧɵɯ ɨɩɰɢɣ ɦɨɠɧɨ ɡɚɞɚɬɶ ɩɟɪɟɞ ɭɤɚɡɚɧɢɟɦ ɢɦɟɧ ɛɚɡ ɞɚɧɧɵɯ ɢ ɬɚɛɥɢɰ. ɍɬɢɥɢɬɚ mysqldump ɩɨɞɞɟɪɠɢɜɚɟɬ ɲɢɪɨɤɢɣ ɩɟɪɟɱɟɧɶ ɨɩɰɢɣ, ɧɨ ɜ ɬɚɛɥ. 14.2 ɩɟɪɟɱɢɫɥɟɧɵ ɥɢɲɶ ɧɚɢɛɨɥɟɟ ɱɚɫɬɨ ɢɫɩɨɥɶɡɭɟɦɵɟ ɨɩɰɢɢ. Òàáëèöà 14.2. Îïöèè óòèëèòû mysqldump Îïöèÿ Îïèñàíèå --add-locks Ââåñòè â ôàéë ñ îïåðàòîðàìè SQL êîìàíäó áëîêèðîâêè òàáëèöû äëÿ îáåñïå÷åíèÿ áîëåå áûñòðîãî âûïîëíåíèÿ îïåðàöèé âñòàâêè äàííûõ â öåëåâóþ òàáëèöó. Ñì. òàêæå --opt --add-drop-table Ïåðåçàïèñàòü îïðåäåëåíèå êàæäîé òàáëèöû. Ïðè èñïîëüçîâàíèè ýòîé îïöèè íåîáõîäèìî ñîáëþäàòü îñòîðîæíîñòü, ïîñêîëüêó ìîæåò ïðîèçîéòè íåïðåäíàìåðåííîå óäàëåíèå äàííûõ! Åñëè ýòà îïöèÿ íå èñïîëüçóåòñÿ, à òàáëèöà ñ òåì æå èìåíåì óæå ñóùåñòâóåò, òî ïîñëå îáðàùåíèÿ ê öåëåâîé áàçå äàííûõ âûðàáàòûâàåòñÿ ñîîáùåíèå îá îøèáêå Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 363 Ɉɤɨɧɱɚɧɢɟ ɬɚɛɥ. 14.2 Îïöèÿ Îïèñàíèå -a, --all Ýòà îïöèÿ çàäàåò ñðàçó âñå âîçìîæíûå îïöèè. Ïðè èñïîëüçîâàíèè ýòîé îïöèè íåîáõîäèìî ñîáëþäàòü îñòîðîæíîñòü! -c, --complete-insert Èñïîëüçîâàòü áîëåå ïîëíûå îïåðàòîðû âñòàâêè, ñ íàçâàíèÿìè ñòîëáöîâ, à íå ïðîñòî ñ÷èòûâàòü çíà÷åíèÿ --help Âûâåñòè ñïðàâî÷íîå ñîîáùåíèå ñ îïèñàíèåì îïöèé -l, --lock-tables Çàáëîêèðîâàòü òàáëèöû â èñõîäíîé áàçå (áàçàõ) äàííûõ ïåðåä ñîçäàíèåì êîïèè -n, --no-create-db Íå ñîçäàâàòü áàçû äàííûõ ñ óêàçàííûìè èìåíàìè, åñëè îíè åùå íå ñóùåñòâóþò. Ýòà îïöèÿ ïðèìåíÿåòñÿ ïî óìîë÷àíèþ, åñëè çàäàíà îïöèÿ --databases èëè --all-databases -t, --no-create-info Íå ñîçäàâàòü òàáëèöû ñ óêàçàííûìè èìåíàìè, åñëè îíè åùå íå ñóùåñòâóþò -d, --no-data Ôîðìèðîâàòü òîëüêî îïåðàòîðû ñ îïðåäåëåíèÿìè ñòðóêòóðû óêàçàííîé áàçû (áàç) äàííûõ èëè òàáëèö --opt Ïðèìåíåíèå ýòîé îïöèè ðàâíîñèëüíî ïðèìåíåíèþ îïöèé --quick --add-drop-table --add-locks --extended-insert --lock-tables è îáåñïå÷èâàåò íàèáîëåå áûñòðîå ñîçäàíèå êîïèè ïî ñðàâíåíèþ ñî âñåìè ïðî÷èìè âîçìîæíûìè âàðèàíòàìè. Åñëè ìîãóò âîçíèêàòü êîíôëèêòû èìåí, òî ñëåäóåò îáÿçàòåëüíî óäàëèòü ñóùåñòâóþùèå òàáëèöû -q, --quick Íå ïðèìåíÿòü áóôåðèçàöèþ -r, --resultfile=filename Âûâåñòè ðåçóëüòèðóþùóþ êîïèþ â óêàçàííûé ôàéë.  îïåðàöèîííîé ñèñòåìå DOS ôîðìèðóþòñÿ ñèìâîëû ñ îáîçíà÷åíèåì êîíöà ñòðîêè â ñòèëå Unix -w, --where= 'condition' Îñóùåñòâëÿòü âûáîðêó ðåçóëüòàòîâ ñ ïðèìåíåíèåì êîíñòðóêöèè WHERE, çàäàííîé â îäèíàðíûõ êàâû÷êàõ ɍɬɢɥɢɬɚ mysqldump ɹɜɥɹɟɬɫɹ ɨɱɟɧɶ ɭɞɨɛɧɨɣ ɜ ɢɫɩɨɥɶɡɨɜɚɧɢɢ, ɩɨɷɬɨɦɭ ɧɚ ɟɟ ɨɫɧɨɜɟ ɦɨɠɟɬ (ɢ ɨɛɹɡɚɬɟɥɶɧɨ ɞɨɥɠɟɧ) ɛɵɬɶ ɫɨɫɬɚɜɥɟɧ ɝɪɚɮɢɤ ɪɟɝɭɥɹɪɧɨɝɨ ɪɟɡɟɪɜɧɨɝɨ ɤɨɩɢɪɨɜɚɧɢɹ. Ⱦɥɹ ɜɵɩɨɥɧɟɧɢɹ ɨɩɟɪɚɰɢɣ, ɩɪɟɞɭɫɦɨɬɪɟɧɧɵɯ ɝɪɚɮɢɤɨɦ ɪɟɡɟɪɜɧɨɝɨ ɤɨɩɢɪɨɜɚɧɢɹ, ɨɱɟɧɶ ɭɞɨɛɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɡɚɞɚɧɢɹ ɞɥɹ ɭɬɢɥɢɬɵ cron. ȿɫɥɢ ɢɡɦɟɧɟɧɢɹ ɜ ɞɚɧɧɵɟ ɜɧɨɫɹɬɫɹ ɨɬɧɨɫɢɬɟɥɶɧɨ ɪɟɞɤɨ, ɬɨ ɞɨɫɬɚɬɨɱɧɨ ɛɭɞɟɬ ɜɵɩɨɥɧɹɬɶ ɪɟɡɟɪɜɧɨɟ ɤɨɩɢɪɨɜɚɧɢɟ ɨɞɢɧ ɪɚɡ ɜ ɧɟɞɟɥɸ ɢɥɢ ɞɜɚ ɪɚɡɚ ɜ ɦɟɫɹɰ, ɚ ɧɚ ɭɡɥɟ ɫ ɞɨɫɬɚɬɨɱɧɨ ɜɵɫɨɤɢɦ ɬɪɚɮɢɤɨɦ ɦɨɠɟɬ ɩɨɬɪɟɛɨɜɚɬɶɫɹ ɡɚɩɥɚɧɢɪɨɜɚɬɶ ɨɩɟɪɚɰɢɸ ɪɟɡɟɪɜɧɨɝɨ ɤɨɩɢɪɨɜɚɧɢɹ ɧɚ ɜɵɩɨɥɧɟɧɢɟ ɨɞɢɧ ɪɚɡ ɜ ɫɭɬɤɢ. ɉɨɥɶɡɨɜɚɬɟɥɢ ɩɪɨɝɪɚɦɦɵ PHPMyAdmin ɩɨɥɭɱɚɸɬ ɞɨɫɬɭɩ ɤ ɭɬɢɥɢɬɟ mysqldump ɫ ɩɨɦɨɳɶɸ ɜɤɥɚɞɤɢ Export. Ɉɞɧɚɤɨ ɜ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɩɪɨɝɪɚɦɦɚ PHPMyAdmin ɩɨɡɜɨɥɹɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶ ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɤɨɩɢɢ ɞɚɧɧɵɯ ɬɨɥɶɤɨ ɧɚɢɛɨɥɟɟ ɩɪɨɫɬɵɟ ɨɩɰɢɢ. Ⱥ ɟɫɥɢ ɬɪɟɛɭɟɬɫɹ ɛɨɥɶɲɢɣ ɤɨɧɬɪɨɥɶ ɧɚɞ ɮɨɪɦɚɬɨɦ ɮɚɣɥɚ ɫ ɤɨɦɚɧɞɚɦɢ SQL, ɬɨ ɫɥɟɞɭɟɬ ɜɦɟɫɬɨ ɷɬɨɝɨ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɭɬɢɥɢɬɭ mysqldump, ɤɚɤ ɨɩɢɫɚɧɨ ɜɵɲɟ. Ðåïëèêàöèÿ Ɇɟɬɨɞ ɪɟɩɥɢɤɚɰɢɢ, ɩɪɢɦɟɧɹɟɦɵɣ ɜ ɛɚɡɟ ɞɚɧɧɵɯ MySQL, ɨɫɧɨɜɚɧ ɧɚ ɦɨɞɟɥɢ ɨɞɧɨɫɬɨɪɨɧɧɟɣ ɪɟɩɥɢɤɚɰɢɢ ɩɨ ɩɪɢɧɰɢɩɭ “ɨɞɢɧ ɜɟɞɭɳɢɣ–ɨɞɢɧ ɢɥɢ ɧɟɫɤɨɥɶɤɨ ɜɟɞɨɦɵɯ”. ȼɟɞɭɳɚɹ ɛɚɡɚ ɞɚɧɧɵɯ ɨɛɟɫɩɟɱɢɜɚɟɬ ɜɵɩɨɥɧɟɧɢɟ ɜɫɟɯ ɨɩɟɪɚɰɢɣ ɡɚɩɢɫɢ. ɉɨɞ ɷɬɢɦ ɩɨɞɪɚɡɭɦɟɜɚɟɬɫɹ ɜɵ- 364 ×àñòü II. PHP è MySQL ɩɨɥɧɟɧɢɟ ɜɫɟɯ ɨɩɟɪɚɰɢɣ INSERT, UPDATE ɢ DELETE, ɚ ɬɚɤɠɟ ɜɧɟɫɟɧɢɟ ɜɫɟɯ ɢɡɦɟɧɟɧɢɣ ɜ ɫɯɟɦɭ. ȼɟɞɨɦɵɟ ɛɚɡɵ ɞɚɧɧɵɯ ɩɟɪɢɨɞɢɱɟɫɤɢ ɩɨɥɭɱɚɸɬ ɨɬ ɜɟɞɭɳɟɣ ɛɚɡɵ ɞɚɧɧɵɯ ɢ ɜɧɨɫɹɬ ɜ ɫɜɨɢ ɬɚɛɥɢɰɵ ɢɧɮɨɪɦɚɰɢɸ ɨɛ ɷɬɢɯ ɢɡɦɟɧɟɧɢɹɯ, ɚ ɜ ɢɧɬɟɪɜɚɥɚɯ ɦɟɠɞɭ ɬɚɤɢɦɢ ɨɩɟɪɚɰɢɹɦɢ ɦɨɞɢɮɢɤɚɰɢɢ ɨɫɬɚɸɬɫɹ ɞɨɫɬɭɩɧɵɦɢ ɞɥɹ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɜ ɤɚɱɟɫɬɜɟ ɜɵɫɨɤɨ ɨɩɬɢɦɢɡɢɪɨɜɚɧɧɵɯ ɫɪɟɞɫɬɜ ɩɪɟɞɨɫɬɚɜɥɟɧɢɹ ɞɚɧɧɵɯ, ɩɪɟɞɧɚɡɧɚɱɟɧɧɵɯ ɬɨɥɶɤɨ ɞɥɹ ɱɬɟɧɢɹ (ɩɨɞ ɷɬɢɦ ɩɨɞɪɚɡɭɦɟɜɚɟɬɫɹ, ɱɬɨ ɜ ɷɬɢ ɢɧɬɟɪɜɚɥɵ ɜɟɞɭɳɢɟ ɛɚɡɵ ɞɚɧɧɵɯ ɜɵɩɨɥɧɹɸɬ ɬɨɥɶɤɨ ɨɩɟɪɚɰɢɢ SELECT). ȼ ɫɜɨɟɣ ɪɚɛɨɬɟ ɜɟɞɭɳɚɹ ɛɚɡɚ ɞɚɧɧɵɯ ɧɢɤɨɢɦ ɨɛɪɚɡɨɦ ɧɟ ɭɱɢɬɵɜɚɟɬ ɫɭɳɟɫɬɜɨɜɚɧɢɟ ɜɟɞɨɦɵɯ ɛɚɡ ɞɚɧɧɵɯ, ɚ ɩɪɨɫɬɨ ɜɧɨɫɢɬ ɡɚɩɢɫɢ ɜ ɞɜɨɢɱɧɵɟ ɠɭɪɧɚɥɵ ɢ ɩɪɟɞɨɫɬɚɜɥɹɟɬ ɞɨɫɬɭɩ ɤ ɷɬɢɦ ɠɭɪɧɚɥɚɦ. ȼɫɟ ɨɫɬɚɥɶɧɵɟ ɞɟɣɫɬɜɢɹ ɜɵɩɨɥɧɹɸɬ ɜɟɞɨɦɵɟ ɛɚɡɵ ɞɚɧɧɵɯ: ɜ ɧɢɯ ɫɨɩɪɨɜɨɠɞɚɟɬɫɹ ɝɪɚɮɢɤ ɨɛɧɨɜɥɟɧɢɣ, ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɩɨɞɤɥɸɱɟɧɢɟ ɤ ɜɟɞɭɳɟɣ ɛɚɡɟ ɞɚɧɧɵɯ, ɫɱɢɬɵɜɚɟɬɫɹ ɢɧɮɨɪɦɚɰɢɹ ɨɛ ɢɡɦɟɧɟɧɢɹɯ, ɷɬɢ ɢɡɦɟɧɟɧɢɹ ɜɧɨɫɹɬɫɹ ɜ ɬɚɛɥɢɰɵ ɢ ɬ.ɞ. Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɜɟɞɨɦɵɟ ɛɚɡɵ ɞɚɧɧɵɯ ɢɦɟɸɬ ɜ ɫɜɨɟɦ ɪɚɫɩɨɪɹɠɟɧɢɢ ɢɞɟɧɬɢɮɢɤɚɰɢɨɧɧɭɸ ɢɧɮɨɪɦɚɰɢɸ, ɤɨɬɨɪɚɹ ɨɩɢɫɵɜɚɟɬ ɜɟɞɭɳɭɸ ɛɚɡɭ ɞɚɧɧɵɯ, ɚ ɜɟɞɭɳɚɹ ɛɚɡɚ ɞɚɧɧɵɯ ɧɟ ɢɦɟɟɬ ɫɜɟɞɟɧɢɣ ɨ ɧɚɥɢɱɢɢ ɜɟɞɨɦɵɯ ɛɚɡ ɞɚɧɧɵɯ. ȿɫɥɢ ɜɟɞɭɳɚɹ ɛɚɡɚ ɞɚɧɧɵɯ ɩɨ ɤɚɤɨɣ-ɥɢɛɨ ɩɪɢɱɢɧɟ ɩɪɟɤɪɚɳɚɟɬ ɫɜɨɸ ɪɚɛɨɬɭ, ɬɨ ɜɵɛɨɪ ɞɪɭɝɨɣ ɛɚɡɵ ɞɚɧɧɵɯ ɞɥɹ ɟɟ ɡɚɦɟɧɵ ɧɟ ɩɪɨɢɫɯɨɞɢɬ ɚɜɬɨɦɚɬɢɱɟɫɤɢ. ɑɚɳɟ ɜɫɟɝɨ ɜɫɹ ɫɢɫɬɟɦɚ ɫɬɚɧɨɜɢɬɫɹ ɧɟɪɚɛɨɬɨɫɩɨɫɨɛɧɨɣ, ɩɨɫɤɨɥɶɤɭ ɜɟɞɨɦɵɟ ɛɚɡɵ ɞɚɧɧɵɯ ɡɚɬɪɚɱɢɜɚɸɬ ɦɧɨɝɨ ɪɟɫɭɪɫɨɜ, ɛɟɡɭɫɩɟɲɧɨ ɩɵɬɚɹɫɶ ɩɨɞɤɥɸɱɢɬɶɫɹ ɤ ɜɟɞɭɳɟɣ ɛɚɡɟ ɞɚɧɧɵɯ ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɨɛɧɨɜɥɟɧɢɣ, ɜ ɬɨ ɜɪɟɦɹ ɤɚɤ ɫɢɫɬɟɦɚ PHP ɩɪɟɞɩɪɢɧɢɦɚɟɬ ɩɨɩɵɬɤɢ ɜɵɩɨɥɧɢɬɶ ɨɩɟɪɚɰɢɢ ɱɬɟɧɢɹ, ɧɨ ɫɞɟɥɚɬɶ ɷɬɨɝɨ ɧɟ ɭɞɚɟɬɫɹ. ɉɪɢ ɬɚɤɢɯ ɨɛɫɬɨɹɬɟɥɶɫɬɜɚɯ ɚɞɦɢɧɢɫɬɪɚɬɨɪ ɛɚɡɵ ɞɚɧɧɵɯ ɞɨɥɠɟɧ ɪɚɡɨɪɜɚɬɶ ɫɭɳɟɫɬɜɭɸɳɢɟ ɫɜɹɡɢ “ɜɟɞɭɳɢɣ–ɜɟɞɨɦɵɣ” ɜɪɭɱɧɭɸ ɢ ɧɚɡɧɚɱɢɬɶ ɧɨɜɭɸ ɜɟɞɭɳɭɸ ɛɚɡɭ ɞɚɧɧɵɯ. Ʉ ɫɱɚɫɬɶɸ, ɜ ɫɥɭɱɚɟ ɜɨɡɧɢɤɧɨɜɟɧɢɹ ɤɚɤɢɯ-ɥɢɛɨ ɧɚɪɭɲɟɧɢɣ ɜ ɪɚɛɨɬɟ ɜɟɞɭɳɟɣ ɛɚɡɵ ɞɚɧɧɵɯ ɢɫɩɪɚɜɧɨɟ ɫɨɫɬɨɹɧɢɟ ɜɟɞɨɦɵɯ ɛɚɡ ɞɚɧɧɵɯ ɧɟ ɦɨɠɟɬ ɛɵɬɶ ɧɚɪɭɲɟɧɨ ɧɢɤɨɢɦ ɨɛɪɚɡɨɦ, ɩɨɷɬɨɦɭ, ɩɪɢ ɭɫɥɨɜɢɢ, ɱɬɨ ɚɞɦɢɧɢɫɬɪɚɬɨɪ ɛɚɡɵ ɞɚɧɧɵɯ ɫɜɨɟɜɪɟɦɟɧɧɨ ɨɛɧɚɪɭɠɢɬ ɜɨɡɧɢɤɧɨɜɟɧɢɟ ɭɤɚɡɚɧɧɨɣ ɩɪɨɛɥɟɦɵ ɢ ɫɦɨɠɟɬ ɫ ɧɟɣ ɫɩɪɚɜɢɬɶɫɹ, ɩɟɪɟɯɨɞ ɧɚ ɧɨɜɭɸ ɜɟɞɭɳɭɸ ɛɚɡɭ ɞɚɧɧɵɯ ɞɨɥɠɟɧ ɩɪɨɢɡɨɣɬɢ ɨɬɧɨɫɢɬɟɥɶɧɨ ɛɵɫɬɪɨ. ȼ ɤɚɠɞɨɣ ɧɨɜɨɣ ɜɟɪɫɢɢ MySQL ɩɨɹɜɥɹɸɬɫɹ ɦɧɨɝɨɱɢɫɥɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ ɢ ɨɛɧɨɜɥɟɧɢɹ, ɤɚɫɚɸɳɢɟɫɹ ɪɟɩɥɢɤɚɰɢɢ, ɩɨɷɬɨɦɭ ɨɞɧɢ ɫɨɜɪɟɦɟɧɧɵɟ ɜɟɪɫɢɢ ɱɚɫɬɨ ɧɟɫɨɜɦɟɫɬɢɦɵ ɫ ɞɪɭɝɢɦɢ ɫɨɜɪɟɦɟɧɧɵɦɢ ɜɟɪɫɢɹɦɢ, ɜɵɩɭɳɟɧɧɵɦɢ ɧɟɦɧɨɝɨ ɪɚɧɶɲɟ ɢɥɢ ɩɨɡɠɟ, ɜ ɬɨɣ ɱɚɫɬɢ, ɤɨɬɨɪɚɹ ɨɬɧɨɫɢɬɫɹ ɤ ɧɚɫɬɪɨɣɤɟ ɫɪɟɞɫɬɜ ɪɟɩɥɢɤɚɰɢɢ. ȼ ɫɜɹɡɢ ɫ ɷɬɢɦ ɨɫɧɨɜɧɚɹ ɪɟɤɨɦɟɧɞɚɰɢɹ ɞɥɹ ɬɟɯ, ɤɬɨ ɠɟɥɚɟɬ ɨɩɪɨɛɨɜɚɬɶ ɫɪɟɞɫɬɜɚ ɪɟɩɥɢɤɚɰɢɢ, ɫɨɫɬɨɢɬ ɜ ɫɥɟɞɭɸɳɟɦ: ɧɟɨɛɯɨɞɢɦɨ ɨɛɟɫɩɟɱɢɬɶ, ɱɬɨɛɵ ɜɫɟ ɢɫɩɨɥɶɡɭɟɦɵɟ ɫɟɪɜɟɪɵ ɛɚɡɵ ɞɚɧɧɵɯ MySQL ɢɦɟɥɢ ɨɞɧɭ ɢ ɬɭ ɠɟ ɜɟɪɫɢɸ. Ȼɨɥɟɟ ɬɨɝɨ, ɷɬɨ ɞɨɥɠɧɚ ɛɵɬɶ ɜɟɪɫɢɹ 4.0.3 ɢɥɢ ɩɨɫɥɟɞɭɸɳɚɹ. ȿɫɥɢ ɠɟ ɛɭɞɟɬ ɩɪɟɞɩɪɢɧɹɬɚ ɩɨɩɵɬɤɚ ɨɪɝɚɧɢɡɨɜɚɬɶ ɪɟɩɥɢɤɚɰɢɸ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɧɟɫɨɜɦɟɫɬɢɦɵɯ ɜɟɪɫɢɣ MySQL (ɧɚɱɢɧɚɹ ɫ 3.23 ɢ ɡɚɤɚɧɱɢɜɚɹ 4.0.3), ɬɨ ɫɨɡɞɚɜɚɟɦɚɹ ɫɢɫɬɟɦɚ ɪɟɩɥɢɤɚɰɢɢ, ɩɨ ɜɫɟɣ ɜɟɪɨɹɬɧɨɫɬɢ, ɧɟ ɛɭɞɟɬ ɪɚɛɨɬɚɬɶ ɞɨɥɠɧɵɦ ɨɛɪɚɡɨɦ. ɉɨ ɫɭɳɟɫɬɜɭ, ɨɩɟɪɚɰɢɢ, ɤɨɬɨɪɵɟ ɞɨɥɠɧɵ ɛɵɬɶ ɜɵɩɨɥɧɟɧɵ ɞɥɹ ɨɪɝɚɧɢɡɚɰɢɢ ɫɢɫɬɟɦɵ ɪɟɩɥɢɤɚɰɢɢ ɧɚ ɨɫɧɨɜɟ MySQL, ɫɨɫɬɨɹɬ ɜ ɫɥɟɞɭɸɳɟɦ. 1. ɉɪɟɞɨɫɬɚɜɢɬɶ ɧɟɨɛɯɨɞɢɦɵɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɤ ɜɟɞɭɳɟɣ ɛɚɡɟ ɞɚɧɧɵɯ ɬɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ, ɨɬ ɢɦɟɧɢ ɤɨɬɨɪɨɝɨ ɪɚɛɨɬɚɸɬ ɜɟɞɨɦɵɟ ɛɚɡɵ ɞɚɧɧɵɯ. 2. ɉɨɥɭɱɢɬɶ ɫɧɢɦɨɤ ɞɚɧɧɵɯ, ɧɚɯɨɞɹɳɢɯɫɹ ɜ ɜɟɞɭɳɟɣ ɛɚɡɟ ɞɚɧɧɵɯ; ɫɤɨɩɢɪɨɜɚɬɶ ɷɬɢ ɞɚɧɧɵɟ ɧɚ ɬɟ ɤɨɦɩɶɸɬɟɪɵ, ɝɞɟ ɧɚɯɨɞɹɬɫɹ ɜɟɞɨɦɵɟ ɛɚɡɵ ɞɚɧɧɵɯ. 3. Ɉɫɬɚɧɨɜɢɬɶ ɫɟɪɜɟɪɵ MySQL. 4. ɉɟɪɟɡɚɩɭɫɬɢɬɶ ɫɟɪɜɟɪɵ MySQL ɩɨɫɥɟ ɡɚɞɚɧɢɹ ɩɪɚɜɢɥɶɧɵɯ ɡɧɚɱɟɧɢɣ ɩɚɪɚɦɟɬɪɚ server-id. 5. ɍɫɬɚɧɨɜɢɬɶ ɞɨɥɠɧɵɦ ɨɛɪɚɡɨɦ ɫɜɹɡɶ “ɜɟɞɭɳɢɣ–ɜɟɞɨɦɵɣ” ɨɬ ɤɚɠɞɨɣ ɜɟɞɨɦɨɣ ɛɚɡɵ ɞɚɧɧɵɯ. ɇɢɠɟ ɷɬɨɬ ɩɪɨɰɟɫɫ ɨɩɢɫɚɧ ɛɨɥɟɟ ɩɨɞɪɨɛɧɨ. Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 365 ȼ ɜɟɞɭɳɟɣ ɛɚɡɟ ɞɚɧɧɵɯ ɧɟɨɛɯɨɞɢɦɨ ɫɨɡɞɚɬɶ ɭɱɟɬɧɭɸ ɡɚɩɢɫɶ, ɩɪɟɞɧɚɡɧɚɱɟɧɧɭɸ ɞɥɹ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɜɟɞɨɦɵɦɢ ɛɚɡɚɦɢ ɞɚɧɧɵɦɢ, ɢ ɩɪɟɞɨɫɬɚɜɢɬɶ ɷɬɨɣ ɭɱɟɬɧɨɣ ɡɚɩɢɫɢ ɩɪɚɜɚ ɞɨɫɬɭɩɚ REPLICATE SLAVE, ɤɚɤ ɩɨɤɚɡɚɧɨ ɧɢɠɟ. Ʉɚɤɢɟ-ɥɢɛɨ ɢɧɵɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɷɬɨɣ ɭɱɟɬɧɨɣ ɡɚɩɢɫɢ ɩɪɟɞɨɫɬɚɜɥɹɬɶ ɧɟ ɬɪɟɛɭɟɬɫɹ. GRANT REPLICATE SLAVE ON *.* TO replicant@'%' IDENTIFIED BY 'replpwd'; Ɂɚɬɟɦ ɧɟɨɛɯɨɞɢɦɨ ɡɚɛɥɨɤɢɪɨɜɚɬɶ ɜɟɞɭɳɢɣ ɫɟɪɜɟɪ ɢ ɩɨɥɭɱɢɬɶ ɫɧɢɦɨɤ ɟɝɨ ɫɨɫɬɨɹɧɢɹ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɩɟɪɟɞ ɪɟɩɥɢɤɚɰɢɟɣ. ɇɚ ɜɟɞɭɳɟɦ ɫɟɪɜɟɪɟ ɡɚɪɟɝɢɫɬɪɢɪɭɣɬɟɫɶ ɜ ɤɥɢɟɧɬɫɤɨɦ ɫɟɚɧɫɟ MySQL ɜ ɤɚɱɟɫɬɜɟ ɩɨɥɶɡɨɜɚɬɟɥɹ root ɢ ɜɵɩɨɥɧɢɬɟ ɫɥɟɞɭɸɳɢɟ ɤɨɦɚɧɞɵ: FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS; ȼɵɩɨɥɧɟɧɢɟ ɷɬɢɯ ɤɨɦɚɧɞ ɩɪɢɜɟɞɟɬ ɤ ɬɨɦɭ, ɱɬɨ ɜɧɟɫɟɧɢɟ ɤɚɤɢɯ-ɥɢɛɨ ɢɡɦɟɧɟɧɢɣ ɜ ɛɚɡɭ ɞɚɧɧɵɯ ɫɬɚɧɟɬ ɧɟɜɨɡɦɨɠɧɵɦ ɞɨ ɬɟɯ ɩɨɪ, ɩɨɤɚ ɜɵ ɧɟ ɛɭɞɟɬɟ ɝɨɬɨɜɵ ɩɟɪɟɜɟɫɬɢ ɜ ɪɚɛɨɱɟɟ ɫɨɫɬɨɹɧɢɟ ɜɟɫɶ ɤɥɚɫɬɟɪ, ɤɨɬɨɪɵɣ ɫɨɫɬɨɢɬ ɢɡ ɜɟɞɭɳɟɣ ɢ ɜɟɞɨɦɵɯ ɛɚɡ ɞɚɧɧɵɯ. ȼɵ ɦɨɠɟɬɟ ɬɚɤɠɟ (ɜ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɬɨɝɨ, ɜɟɞɟɬɫɹ ɥɢ ɷɤɫɩɥɭɚɬɚɰɢɹ ɞɚɧɧɨɝɨ ɫɟɪɜɟɪɚ ɜ ɪɟɠɢɦɟ ɜɟɞɟɧɢɹ ɠɭɪɧɚɥɨɜ ɜ ɞɜɨɢɱɧɨɦ ɮɨɪɦɚɬɟ) ɨɡɧɚɤɨɦɢɬɶɫɹ ɫ ɧɟɤɨɬɨɪɵɦɢ ɞɚɧɧɵɦɢ ɨ ɦɟɫɬɨɧɚɯɨɠɞɟɧɢɢ ɮɚɣɥɚ ɞɜɨɢɱɧɨɝɨ ɠɭɪɧɚɥɚ ɢ ɫɦɟɳɟɧɢɢ. ȿɫɥɢ ɬɚɤɢɟ ɞɚɧɧɵɟ ɢɦɟɸɬɫɹ, ɬɨ ɡɚɩɢɲɢɬɟ ɢɯ ɧɚ ɛɭɦɚɝɟ, ɚ ɜ ɩɪɨɬɢɜɧɨɦ ɫɥɭɱɚɟ ɢɫɩɨɥɶɡɭɣɬɟ ɩɪɟɞɭɫɦɨɬɪɟɧɧɵɟ ɩɨ ɭɦɨɥɱɚɧɢɸ ɡɧɚɱɟɧɢɹ, ɫɨɨɬɜɟɬɫɬɜɟɧɧɨ '' (ɩɭɫɬɚɹ ɫɬɪɨɤɚ) ɢ 4. Ɂɚɬɟɦ ɫɤɨɩɢɪɭɣɬɟ ɫɬɪɭɤɬɭɪɭ ɢ ɞɚɧɧɵɟ ɜɟɞɭɳɟɣ ɛɚɡɵ ɞɚɧɧɵɯ. Ⱦɥɹ ɜɵɩɨɥɧɟɧɢɹ ɷɬɨɣ ɨɩɟɪɚɰɢɢ ɦɨɠɧɨ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɞɜɭɦɹ ɫɩɨɫɨɛɚɦɢ. ɉɟɪɜɵɣ ɢɡ ɧɢɯ ɫɨɫɬɨɢɬ ɜ ɤɨɩɢɪɨɜɚɧɢɢ ɤɚɬɚɥɨɝɚ mysql/data ɜ ɮɚɣɥ ɮɨɪɦɚɬɚ tar ɢɥɢ ɮɚɣɥ ɮɨɪɦɚɬɚ zip ɫ ɩɨɦɨɳɶɸ ɨɞɧɨɣ ɢɡ ɫɥɟɞɭɸɳɢɯ ɤɨɦɚɧɞ (ɢɥɢ ɩɪɨɰɟɞɭɪɵ ɫ ɝɪɚɮɢɱɟɫɤɢɦ ɢɧɬɟɪɮɟɣɫɨɦ): tar -cvf master_snapshot.tar data/ zip master_snapshot.zip data/ ȼɬɨɪɨɣ ɫɩɨɫɨɛ ɫɨɫɬɨɢɬ ɜ ɬɨɦ, ɱɬɨ ɦɨɠɟɬ ɛɵɬɶ ɫɨɡɞɚɧɚ ɪɟɡɟɪɜɧɚɹ ɤɨɩɢɹ ɫ ɩɨɦɨɳɶɸ ɭɬɢɥɢɬɵ mysqldump, ɤɚɤ ɨɩɢɫɚɧɨ ɜ ɫɥɟɞɭɸɳɟɦ ɪɚɡɞɟɥɟ. ɋɤɨɩɢɪɭɣɬɟ ɩɨɥɭɱɟɧɧɵɣ ɮɚɣɥ ɫɧɢɦɤɚ ɧɚ ɤɚɠɞɵɣ ɜɟɞɨɦɵɣ ɫɟɪɜɟɪ. Ɍɟɩɟɪɶ ɨɫɬɚɧɨɜɢɬɟ ɜɫɟ ɫɟɪɜɟɪɵ, ɜɟɞɭɳɢɣ ɢ ɜɟɞɨɦɵɣ (ɜɟɞɨɦɵɟ). Ɂɚɤɪɨɣɬɟ ɜɫɟ ɫɟɚɧɫɵ ɤɥɢɟɧɬɫɤɨɝɨ ɤɨɦɚɧɞɧɨɝɨ ɢɧɬɟɪɩɪɟɬɚɬɨɪɚ mysql ɢ ɜɜɟɞɢɬɟ ɫɥɟɞɭɸɳɭɸ ɤɨɦɚɧɞɭ ɨɫɬɚɧɨɜɚ ɧɚ ɤɚɠɞɨɦ ɫɟɪɜɟɪɟ: mysqladmin -u root -p shutdown ɇɟɨɛɯɨɞɢɦɨɫɬɶ ɜ ɨɫɬɚɧɨɜɟ ɫɟɪɜɟɪɨɜ ɫɜɹɡɚɧɚ ɫ ɬɟɦ, ɱɬɨ ɫɟɪɜɟɪɚɦ, ɭɱɚɫɬɜɭɸɳɢɦ ɜ ɪɟɩɥɢɤɚɰɢɢ, ɞɨɥɠɧɵ ɛɵɬɶ ɩɪɢɫɜɨɟɧɵ ɭɧɢɤɚɥɶɧɵɟ ɡɧɚɱɟɧɢɹ ɩɚɪɚɦɟɬɪɚ server-id. ɋɟɪɜɟɪɵ ɢɫɩɨɥɶɡɭɸɬ ɷɬɢ ɡɧɚɱɟɧɢɹ, ɱɬɨɛɵ ɧɚɣɬɢ ɞɪɭɝ ɞɪɭɝɚ ɜ ɯɨɞɟ ɭɫɬɚɧɨɜɥɟɧɢɹ ɫɜɹɡɟɣ “ɜɟɞɭɳɢɣ–ɜɟɞɨɦɵɣ”. Ɂɧɚɱɟɧɢɟ server-id ɡɚɞɚɟɬɫɹ ɜ ɮɚɣɥɟ my.cnf ɤɚɠɞɨɝɨ ɫɟɪɜɟɪɚ ɢ ɫɱɢɬɵɜɚɟɬɫɹ ɩɪɢ ɡɚɩɭɫɤɟ. ȼ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɟ Windows ɮɚɣɥ my.cnf ɦɨɠɟɬ ɧɚɯɨɞɢɬɶɫɹ ɥɢɛɨ ɜ C:\my.cnf, ɥɢɛɨ ɜ C:\[Windows directory]\my.ini. ȼ ɨɩɟɪɚɰɢɨɧɧɵɯ ɫɢɫɬɟɦɚɯ ɬɢɩɚ Unix ɝɥɨɛɚɥɶɧɵɣ ɮɚɣɥ my.cnf ɧɚɯɨɞɢɬɫɹ ɩɨ ɚɞɪɟɫɭ /etc/my.cnf, ɚ ɮɚɣɥ, ɨɬɧɨɫɹɳɢɣɫɹ ɤ ɤɨɧɤɪɟɬɧɨɦɭ ɫɟɪɜɟɪɭ (ɚ ɩɪɢ ɧɚɫɬɪɨɣɤɟ ɫɢɫɬɟɦɵ ɪɟɩɥɢɤɚɰɢɢ ɞɨɥɠɟɧ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɢɦɟɧɧɨ ɷɬɨɬ ɮɚɣɥ), ɧɚɯɨɞɢɬɫɹ ɩɨ ɚɞɪɟɫɭ /path/to/mysql/data/my.cnf. ȼɧɚɱɚɥɟ ɧɟɨɛɯɨɞɢɦɨ ɡɚɞɚɬɶ ɡɧɚɱɟɧɢɟ server-id ɧɚ ɤɨɦɩɶɸɬɟɪɟ ɜɟɞɭɳɟɝɨ ɫɟɪɜɟɪɚ. ɇɚɣɞɢɬɟ ɢɥɢ ɫɨɡɞɚɣɬɟ ɮɚɣɥ my.cnf ɜ ɬɨɦ ɤɚɬɚɥɨɝɟ, ɤɨɬɨɪɵɣ ɞɨɥɠɟɧ ɩɪɢɦɟɧɹɬɶɫɹ ɞɥɹ ɪɚɡɦɟɳɟɧɢɹ ɷɬɨɝɨ ɮɚɣɥɚ ɧɚ ɤɨɧɤɪɟɬɧɨɣ ɩɥɚɬɮɨɪɦɟ, ɢ ɭɛɟɞɢɬɟɫɶ ɜ ɬɨɦ, ɱɬɨ ɷɬɨɬ ɮɚɣɥ ɫɨɞɟɪɠɢɬ ɬɚɤɢɟ ɫɬɪɨɤɢ: [mysqld] log-bin server-id=1 366 ×àñòü II. PHP è MySQL ɉɟɪɟɡɚɩɭɫɬɢɬɟ ɜɟɞɭɳɢɣ ɫɟɪɜɟɪ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: bin/mysqld_safe --user=mysql ȼ ɮɚɣɥɟ my.cnf ɤɚɠɞɨɝɨ ɜɟɞɨɦɨɝɨ ɫɟɪɜɟɪɚ ɬɪɟɛɭɟɬɫɹ ɬɨɥɶɤɨ ɫɬɪɨɤɚ server-id, ɧɨ ɧɟ ɫɬɪɨɤɚ log-bin. ɇɚɢɛɨɥɟɟ ɜɚɠɧɨɟ ɬɪɟɛɨɜɚɧɢɟ ɫɨɫɬɨɢɬ ɜ ɬɨɦ, ɱɬɨɛɵ ɜɫɟ ɡɧɚɱɟɧɢɹ server-id ɜ ɤɚɠɞɨɦ ɤɨɧɤɪɟɬɧɨɦ ɤɥɚɫɬɟɪɟ ɪɟɩɥɢɤɚɰɢɢ ɛɵɥɢ ɭɧɢɤɚɥɶɧɵɦɢ! ɗɬɨ ɬɪɟɛɨɜɚɧɢɟ ɹɜɥɹɟɬɫɹ ɤɚɬɟɝɨɪɢɱɟɫɤɢɦ, ɢ ɟɫɥɢ ɨɧɨ ɧɟ ɫɨɛɥɸɞɚɟɬɫɹ, ɬɨ ɜɨɡɧɢɤɚɸɬ ɫɟɪɶɟɡɧɵɟ ɧɚɪɭɲɟɧɢɹ ɜ ɪɚɛɨɬɟ. ɉɨɷɬɨɦɭ ɮɚɣɥ my.cnf ɩɟɪɜɨɝɨ ɜɟɞɨɦɨɝɨ ɫɟɪɜɟɪɚ ɞɨɥɠɟɧ ɫɨɞɟɪɠɚɬɶ ɬɚɤɢɟ ɫɬɪɨɤɢ: [mysqld] server-id=2 ȼ ɬɚɤɨɦ ɫɥɭɱɚɟ ɜ ɮɚɣɥɟ ɜɬɨɪɨɝɨ ɜɟɞɨɦɨɝɨ ɫɟɪɜɟɪɚ ɦɨɠɧɨ ɡɚɞɚɬɶ server-id=3 ɢ ɬ.ɞ. Ɍɟɩɟɪɶ, ɩɟɪɟɞ ɩɟɪɟɜɨɞɨɦ ɜ ɪɚɛɨɱɟɟ ɫɨɫɬɨɹɧɢɟ ɤɚɠɞɨɝɨ ɜɟɞɨɦɨɝɨ ɫɟɪɜɟɪɚ, ɧɟɨɛɯɨɞɢɦɨ ɜɵɩɨɥɧɢɬɶ ɧɟɛɨɥɶɲɭɸ ɜɫɩɨɦɨɝɚɬɟɥɶɧɭɸ ɪɚɛɨɬɭ. ȿɫɥɢ ɤɚɤɨɣ-ɬɨ ɫɟɪɜɟɪ MySQL ɭɠɟ ɢɫɩɨɥɶɡɨɜɚɥɫɹ ɜ ɤɚɱɟɫɬɜɟ ɜɟɞɨɦɨɝɨ, ɧɟɨɛɯɨɞɢɦɨ ɭɞɚɥɢɬɶ ɮɚɣɥɵ data/master.info ɢ data/relay-log. info. Ʉɪɨɦɟ ɬɨɝɨ, ɜ ɤɚɬɚɥɨɝɟ data ɬɪɟɛɭɟɬɫɹ ɭɞɚɥɢɬɶ ɮɚɣɥɵ .err ɢ .pid. Ʉ ɬɨɦɭ ɠɟ, ɟɫɥɢ ɫɧɢɦɨɤ ɞɚɧɧɵɯ ɜɟɞɭɳɟɣ ɛɚɡɵ ɞɚɧɧɵɯ ɫɤɨɩɢɪɨɜɚɧ ɧɚ ɤɨɦɩɶɸɬɟɪ ɜɟɞɨɦɨɣ ɛɚɡɵ ɞɚɧɧɵɯ ɜ ɜɢɞɟ ɮɚɣɥɚ ɮɨɪɦɚɬɚ tar ɢɥɢ zip, ɬɨ ɧɚ ɞɚɧɧɨɦ ɷɬɚɩɟ ɧɟɨɛɯɨɞɢɦɨ ɪɚɡɜɟɪɧɭɬɶ ɷɬɨɬ ɮɚɣɥ ɫ ɩɨɦɨɳɶɸ ɨɞɧɨɣ ɢɡ ɫɥɟɞɭɸɳɢɯ ɤɨɦɚɧɞ (ɷɬɭ ɤɨɦɚɧɞɭ ɧɟɨɛɯɨɞɢɦɨ ɜɵɩɨɥɧɢɬɶ ɩɨɫɥɟ ɩɟɪɟɯɨɞɚ ɜ ɤɚɬɚɥɨɝ mysql): tar -xvf master_snapshot.tar unzip master_snapshot.zip ȿɫɥɢ ɠɟ ɜɦɟɫɬɨ ɷɬɨɝɨ ɩɪɢɦɟɧɹɥɚɫɶ ɭɬɢɥɢɬɚ mysqldump, ɬɨ ɧɟɨɛɯɨɞɢɦɨ ɩɨɞɨɠɞɚɬɶ, ɩɨɤɚ ɫɟɪɜɟɪ ɧɟ ɛɭɞɟɬ ɡɚɩɭɳɟɧ. Ɍɟɩɟɪɶ ɜɵɩɨɥɧɢɬɟ ɡɚɩɭɫɤ ɜɟɞɨɦɨɝɨ ɫɟɪɜɟɪɚ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: bin/mysqld_safe --user=mysql --skip-slave-start --log-warnings ȿɫɥɢ ɫɧɢɦɨɤ ɞɚɧɧɵɯ ɜɟɞɭɳɟɣ ɛɚɡɵ ɞɚɧɧɵɯ ɛɵɥ ɩɨɥɭɱɟɧ ɫ ɩɨɦɨɳɶɸ ɭɬɢɥɢɬɵ mysqldump, ɬɨ ɧɚ ɞɚɧɧɨɦ ɷɬɚɩɟ ɦɨɠɧɨ ɩɪɢɦɟɧɢɬɶ ɩɨɥɭɱɟɧɧɵɣ ɮɚɣɥ ɫ ɤɨɦɚɧɞɚɦɢ SQL ɤ ɜɟɞɨɦɨɣ ɛɚɡɟ ɞɚɧɧɵɯ, ɤɚɤ ɩɨɤɚɡɚɧɨ ɧɢɠɟ. mysql -u root -p databasename < master_snapshot.sql ɇɚɤɨɧɟɰ, ɧɟɨɛɯɨɞɢɦɨ ɭɫɬɚɧɨɜɢɬɶ ɫɜɹɡɶ “ɜɟɞɭɳɢɣ–ɜɟɞɨɦɵɣ”. Ɂɚɪɟɝɢɫɬɪɢɪɭɣɬɟɫɶ ɜ ɤɨɦɚɧɞɧɨɦ ɢɧɬɟɪɩɪɟɬɚɬɨɪɟ mysql, ɚ ɡɚɬɟɦ ɜɜɟɞɢɬɟ ɫɥɟɞɭɸɳɢɟ ɤɨɦɚɧɞɵ, ɩɨɞɫɬɚɜɥɹɹ ɡɧɚɱɟɧɢɹ, ɡɚɩɢɫɚɧɧɵɟ ɧɚ ɛɭɦɚɝɟ ɜ ɧɚɱɚɥɟ ɩɪɨɰɟɫɫɚ ɧɚɫɬɪɨɣɤɢ: CHANGE MASTER TO MASTER_HOST='masterhostname', MASTER_USER='replicant', MASTER_PASSWORD='replpwd', MASTER_LOG_FILE='', MASTER_LOG_POS=4; START SLAVE; ȿɫɥɢ ɜɨɡɧɢɤɚɸɬ ɤɚɤɢɟ-ɥɢɛɨ ɩɪɨɛɥɟɦɵ, ɬɨ ɫ ɢɧɮɨɪɦɚɰɢɟɣ ɨ ɧɢɯ ɦɨɠɧɨ ɨɡɧɚɤɨɦɢɬɶɫɹ, ɩɪɨɫɦɨɬɪɟɜ ɠɭɪɧɚɥ ɨɲɢɛɨɤ ɜɟɞɨɦɨɝɨ ɫɟɪɜɟɪɚ. Âîññòàíîâëåíèå ȼ ɨɛɵɱɧɵɯ ɭɫɥɨɜɢɹɯ ɛɚɡɚ ɞɚɧɧɵɯ MySQL ɧɟ ɬɪɟɛɭɟɬ ɛɨɥɶɲɨɝɨ ɜɧɢɦɚɧɢɹ. ɋɟɪɜɟɪɵ MySQL ɭɫɩɟɲɧɨ ɪɚɛɨɬɚɸɬ ɜ ɬɟɱɟɧɢɟ ɦɧɨɝɢɯ ɦɟɫɹɰɟɜ ɢɥɢ ɞɚɠɟ ɥɟɬ ɩɪɢ ɦɢɧɢɦɚɥɶɧɨɦ ɨɛɴɟɦɟ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ. Ɉɞɧɚɤɨ ɫ ɞɚɧɧɵɦɢ ɬɨɠɟ ɜɨɡɧɢɤɚɸɬ ɧɟɩɪɢɹɬɧɨɫɬɢ — ɥɨɦɚɸɬɫɹ ɠɟɫɬɤɢɟ Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 367 ɞɢɫɤɢ, ɧɚ ɰɟɧɬɪɚɯ ɯɨɫɬɢɧɝɚ ɜɧɟɡɚɩɧɨ ɩɪɨɩɚɞɚɟɬ ɩɢɬɚɧɢɟ, ɚ ɨɲɢɛɤɢ ɥɸɞɟɣ ɜɫɟɝɞɚ ɨɫɬɚɸɬɫɹ ɩɨɫɬɨɹɧɧɨɣ ɢ ɧɟɢɡɛɟɠɧɨɣ ɭɝɪɨɡɨɣ. ȿɫɥɢ ɠɟ ɧɚ ɫɟɪɜɟɪɟ ɧɟ ɯɜɚɬɚɟɬ ɨɩɟɪɚɬɢɜɧɨɣ ɩɚɦɹɬɢ ɞɥɹ ɜɫɟɯ ɷɤɫɩɥɭɚɬɢɪɭɟɦɵɯ ɩɪɢɥɨɠɟɧɢɣ ɢɥɢ ɫɬɚɧɨɜɢɬɫɹ ɧɟɞɨɫɬɚɬɨɱɧɵɦ ɨɛɴɟɦ ɞɢɫɤɨɜɨɝɨ ɩɪɨɫɬɪɚɧɫɬɜɚ ɜ ɪɚɡɞɟɥɟ, ɨɬɜɟɞɟɧɧɨɦ ɞɥɹ ɛɚɡɵ ɞɚɧɧɵɯ, ɬɚɤɠɟ ɦɨɠɟɬ ɜɨɡɧɢɤɧɭɬɶ ɨɲɢɛɤɚ, ɤɨɬɨɪɚɹ ɩɨɬɪɟɛɭɟɬ ɩɪɨɜɟɞɟɧɢɹ ɩɪɨɰɟɫɫɚ ɜɨɫɫɬɚɧɨɜɥɟɧɢɹ. ɋɥɟɞɭɟɬ ɩɪɢɡɧɚɬɶ, ɱɬɨ ɜ ɯɨɞɟ ɷɤɫɩɥɭɚɬɚɰɢɢ ɫɟɪɜɟɪɚ MySQL, ɩɨ ɫɪɚɜɧɟɧɢɸ ɫ ɛɨɥɟɟ ɦɨɳɧɵɦɢ ɛɚɡɚɦɢ ɞɚɧɧɵɯ, ɜɟɪɨɹɬɧɨ, ɱɚɳɟ ɜɨɡɧɢɤɚɸɬ ɫɨɛɵɬɢɹ, ɫɜɹɡɚɧɧɵɟ ɫ ɧɟɛɨɥɶɲɢɦɢ ɢɫɤɚɠɟɧɢɹɦɢ ɞɚɧɧɵɯ ɜ ɛɚɡɟ ɞɚɧɧɵɯ. Ⱥ ɜɨɡɦɨɠɧɨ, ɩɪɨɫɬɨ ɚɞɦɢɧɢɫɬɪɚɬɨɪɭ ɛɚɡɵ ɞɚɧɧɵɯ MySQL ɥɟɝɱɟ ɨɛɧɚɪɭɠɢɬɶ ɬɚɤɢɟ ɫɨɛɵɬɢɹ. Ʉ ɫɱɚɫɬɶɸ, ɛɚɡɚ ɞɚɧɧɵɯ MySQL ɫɩɪɨɟɤɬɢɪɨɜɚɧɚ ɬɚɤɢɦ ɨɛɪɚɡɨɦ, ɱɬɨ ɩɨɡɜɨɥɹɟɬ ɭɞɢɜɢɬɟɥɶɧɨ ɥɟɝɤɨ ɢɫɩɪɚɜɢɬɶ ɧɟɛɨɥɶɲɢɟ ɞɟɮɟɤɬɵ ɜ ɞɚɧɧɵɯ ɢ ɱɟɪɟɡ ɤɨɪɨɬɤɨɟ ɜɪɟɦɹ ɫɧɨɜɚ ɩɟɪɟɜɟɫɬɢ ɛɚɡɭ ɞɚɧɧɵɯ ɜ ɪɚɛɨɱɟɟ ɫɨɫɬɨɹɧɢɟ. Ɍɨɥɶɤɨ ɨɞɧɚɠɞɵ ɧɚɦ ɩɪɢɲɥɨɫɶ ɮɚɤɬɢɱɟɫɤɢ ɫɧɨɜɚ ɫɨɡɞɚɬɶ ɜɫɸ ɛɚɡɭ ɞɚɧɧɵɯ ɢɡ ɪɟɡɟɪɜɧɨɣ ɤɨɩɢɢ ɩɨɫɥɟ ɧɟɭɞɚɱɧɨɝɨ ɡɚɜɟɪɲɟɧɢɹ ɦɧɨɝɨɤɪɚɬɧɵɯ ɩɨɩɵɬɨɤ ɜɨɫɫɬɚɧɨɜɥɟɧɢɹ, ɩɪɢɬɨɦ ɱɬɨ ɫɚɦɚ ɚɜɚɪɢɹ ɛɵɥɚ ɜɵɡɜɚɧɚ ɩɨɥɧɵɦ ɨɬɤɚɡɨɦ ɠɟɫɬɤɨɝɨ ɞɢɫɤɚ. ɇɨ ɜ ɩɪɟɞɜɢɞɟɧɢɢ ɬɚɤɨɣ ɫɢɬɭɚɰɢɢ ɪɚɡɪɚɛɨɬɱɢɤ ɧɟ ɦɨɠɟɬ ɫɨɫɬɚɜɢɬɶ ɩɪɨɞɭɤɬɢɜɧɵɣ ɩɥɚɧ ɢɥɢ ɩɨɞɝɨɬɨɜɢɬɶ ɢɡɹɳɧɭɸ ɩɪɨɰɟɞɭɪɭ ɜɨɫɫɬɚɧɨɜɥɟɧɢɹ, ɜ ɤɨɬɨɪɵɯ ɛɵ ɧɟ ɭɱɢɬɵɜɚɥɨɫɶ ɬɪɟɛɨɜɚɧɢɟ ɩɨ ɫɜɨɟɜɪɟɦɟɧɧɨɦɭ ɫɨɡɞɚɧɢɸ ɪɟɡɟɪɜɧɵɯ ɤɨɩɢɣ. ȼ ɫɨɫɬɚɜ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ MySQL ɭɠɟ ɜ ɬɟɱɟɧɢɟ ɞɥɢɬɟɥɶɧɨɝɨ ɜɪɟɦɟɧɢ ɜɯɨɞɢɬ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɟ ɫɪɟɞɫɬɜɨ ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ, ɧɚɡɵɜɚɟɦɨɣ myisamchk, ɤɨɬɨɪɨɟ ɩɪɟɞɧɚɡɧɚɱɟɧɨ ɞɥɹ ɩɪɨɜɟɪɤɢ ɢ ɢɫɩɪɚɜɥɟɧɢɹ ɬɚɛɥɢɰ. ɗɬɨ — ɭɞɨɛɧɵɣ ɫɰɟɧɚɪɢɣ, ɧɨ ɨɬɥɢɱɚɟɬɫɹ ɨɞɧɢɦ ɧɟɞɨɫɬɚɬɤɨɦ — ɟɝɨ ɷɮɮɟɤɬɢɜɧɨɟ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɜɨɡɦɨɠɧɨ, ɬɨɥɶɤɨ ɟɫɥɢ ɛɚɡɚ ɞɚɧɧɵɯ ɨɫɬɚɧɨɜɥɟɧɚ. ɗɬɨɬ ɧɟɞɨɫɬɚɬɨɤ ɨɫɬɚɟɬɫɹ ɜɩɨɥɧɟ ɬɟɪɩɢɦɵɦ, ɟɫɥɢ ɫ ɩɨɦɨɳɶɸ ɫɰɟɧɚɪɢɹ myisamchk ɮɚɤɬɢɱɟɫɤɢ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɜɨɫɫɬɚɧɨɜɥɟɧɢɟ ɩɨɫɥɟ ɚɜɚɪɢɢ, ɩɨɫɤɨɥɶɤɭ ɬɚɤ ɢɥɢ ɢɧɚɱɟ ɡɚɩɭɫɤ ɛɚɡɵ ɞɚɧɧɵɯ ɫ ɧɟɢɫɩɪɚɜɧɵɦɢ ɬɚɛɥɢɰɚɦɢ ɫɬɚɧɨɜɢɬɫɹ ɧɟɜɨɡɦɨɠɧɵɦ, ɧɨ ɟɫɥɢ ɬɪɟɛɭɟɬɫɹ ɨɛɟɫɩɟɱɢɬɶ ɩɪɟɞɨɬɜɪɚɳɟɧɢɟ ɜɨɡɦɨɠɧɵɯ ɩɪɨɛɥɟɦ ɩɭɬɟɦ ɪɟɝɭɥɹɪɧɨɣ ɩɪɨɜɟɪɤɢ ɬɚɛɥɢɰ ɫ ɞɚɧɧɵɦɢ, ɬɨ ɭɤɚɡɚɧɧɵɣ ɧɟɞɨɫɬɚɬɨɤ ɫɬɚɧɨɜɢɬɫɹ ɜɟɫɶɦɚ ɫɭɳɟɫɬɜɟɧɧɵɦ. Ʉ ɫɱɚɫɬɶɸ, ɜ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɢɦɟɟɬɫɹ ɧɨɜɨɟ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɟ ɫɪɟɞɫɬɜɨ ɩɪɨɜɟɪɤɢ, ɤɨɬɨɪɨɟ ɦɨɠɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɜ ɯɨɞɟ ɷɤɫɩɥɭɚɬɚɰɢɢ ɫɟɪɜɟɪɚ, — mysqlcheck. ɋ ɞɪɭɝɨɣ ɫɬɨɪɨɧɵ, ɦɨɠɧɨ ɩɪɨɞɨɥɠɚɬɶ ɩɪɢɦɟɧɹɬɶ myisamchk ɜ ɬɨɬ ɩɟɪɢɨɞ, ɤɨɝɞɚ ɫɟɪɜɟɪ ɧɟ ɪɚɛɨɬɚɟɬ. Ɉɛɚ ɷɬɢ ɭɤɚɡɚɧɧɵɟ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɟ ɫɪɟɞɫɬɜɚ ɩɨ ɫɭɳɟɫɬɜɭ ɜɵɩɨɥɧɹɸɬ ɬɚɤɢɟ ɞɟɣɫɬɜɢɹ: ɩɪɨɜɟɪɹɸɬ ɬɚɛɥɢɰɭ MyISAM ɧɚ ɧɚɥɢɱɢɟ ɨɲɢɛɨɤ, ɢɫɩɪɚɜɥɹɸɬ ɨɛɧɚɪɭɠɟɧɧɵɟ ɨɲɢɛɤɢ ɢ ɨɩɬɢɦɢɡɢɪɭɸɬ ɛɚɡɭ ɞɚɧɧɵɯ. ɇɨ ɞɥɹ ɜɵɡɨɜɚ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɯ ɫɰɟɧɚɪɢɟɜ ɧɚ ɜɵɩɨɥɧɟɧɢɟ ɩɪɢɦɟɧɹɸɬɫɹ ɪɚɡɧɵɟ ɫɢɧɬɚɤɫɢɱɟɫɤɢɟ ɤɨɧɫɬɪɭɤɰɢɢ. Óòèëèòà myisamchk Ⱦɥɹ ɜɵɡɨɜɚ ɭɬɢɥɢɬɵ myisamchk ɩɪɢɦɟɧɹɟɬɫɹ ɩɪɢɦɟɪɧɨ ɬɚɤɚɹ ɤɨɦɚɧɞɚ: myisamchk [options] table_name ɢɥɢ ɬɚɤɚɹ: myisamchk [options] /path/to/mysql/data/database/table.MYI ȼɦɟɫɬɨ ɢɦɟɧ ɤɚɬɚɥɨɝɨɜ ɛɚɡɵ ɞɚɧɧɵɯ database ɢ ɢɦɟɧ ɬɚɛɥɢɰ table ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɩɨɞɫɬɚɧɨɜɨɱɧɵɣ ɫɢɦɜɨɥ — ɡɜɟɡɞɨɱɤɭ, ɩɪɢɱɟɦ ɬɚɤɨɣ ɮɨɪɦɚɬ ɤɨɦɚɧɞɵ ɮɚɤɬɢɱɟɫɤɢ ɩɪɢɦɟɧɹɟɬɫɹ ɱɚɳɟ, ɱɟɦ ɮɨɪɦɚɬ ɫ ɭɤɚɡɚɧɢɟɦ ɢɦɟɧɢ ɬɚɛɥɢɰɵ, ɩɨɫɤɨɥɶɤɭ ɨɛɵɱɧɨ ɧɟɥɶɡɹ ɡɚɪɚɧɟɟ ɨɩɪɟɞɟɥɢɬɶ, ɤɚɤɚɹ ɬɚɛɥɢɰɚ ɹɜɥɹɟɬɫɹ ɢɫɬɨɱɧɢɤɨɦ ɩɪɨɛɥɟɦ. Ⱦɥɹ ɩɪɨɜɟɪɤɢ ɜɫɟɯ ɬɚɛɥɢɰ ɜɨ ɜɫɟɯ ɛɚɡɚɯ ɞɚɧɧɵɯ ɧɚ ɫɟɪɜɟɪɧɨɦ ɤɨɦɩɶɸɬɟɪɟ ɢɫɩɨɥɶɡɭɸɬɫɹ ɫɥɟɞɭɸɳɢɟ ɤɨɦɚɧɞɵ: myisamchk [options] /path/to/mysql/data/*/*.MYI myisamchk [options] /path/to/mysql/data/*/*.MYD Ɋɚɫɲɢɪɟɧɢɟ .MYI ɨɬɧɨɫɢɬɫɹ ɤ ɢɧɞɟɤɫɧɵɦ ɮɚɣɥɚɦ, ɚ ɪɚɫɲɢɪɟɧɢɟ .MYD — ɤ ɮɚɣɥɚɦ ɞɚɧɧɵɯ; ɧɟɨɛɯɨɞɢɦɨ ɩɪɨɜɨɞɢɬɶ ɩɪɨɜɟɪɤɭ ɬɟɯ ɢ ɞɪɭɝɢɯ. 368 ×àñòü II. PHP è MySQL ȿɫɥɢ ɨɩɰɢɢ ɧɟ ɡɚɞɚɧɵ, ɬɨ ɭɬɢɥɢɬɚ myisamchk ɩɪɨɫɬɨ ɩɪɨɜɟɪɹɟɬ ɭɤɚɡɚɧɧɭɸ ɬɚɛɥɢɰɭ. ȿɫɥɢ ɠɟ ɭɤɚɡɚɧɚ ɨɩɰɢɹ -r, ɬɨ ɭɬɢɥɢɬɚ myisamchk ɜɨɫɫɬɚɧɚɜɥɢɜɚɟɬ ɭɤɚɡɚɧɧɵɟ ɬɚɛɥɢɰɵ. ɋ ɩɨɦɨɳɶɸ ɷɬɨɣ ɭɬɢɥɢɬɵ ɦɨɠɧɨ ɬɚɤɠɟ ɩɪɨɜɟɪɢɬɶ ɢ ɜɨɫɫɬɚɧɨɜɢɬɶ ɥɸɛɵɟ ɩɨɜɪɟɠɞɟɧɧɵɟ ɬɚɛɥɢɰɵ ɜ ɨɞɧɨɣ ɨɩɟɪɚɰɢɢ: myisamchk --silent --force --fast --update-state -O key_buffer=64M -O sort_buffer=64M -O read_buffer=1 -O write_buffer=1M /path/to/mysql/data/*/*.MYI Ʉɪɨɦɟ ɬɨɝɨ, ɤɨɦɚɧɞɚ myisamchk -r tablename ɨɩɬɢɦɢɡɢɪɭɟɬ ɫɬɪɭɤɬɭɪɭ ɬɚɛɥɢɰɵ, ɮɪɚɝɦɟɧɬɢɪɨɜɚɧɧɨɣ ɜ ɪɟɡɭɥɶɬɚɬɟ ɜɵɩɨɥɧɟɧɢɹ ɨɩɟɪɚɰɢɣ ɭɞɚɥɟɧɢɹ ɢ ɨɛɧɨɜɥɟɧɢɹ. Óòèëèòà mysqlcheck ɇɨɜɨɟ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɟ ɫɪɟɞɫɬɜɨ mysqlcheck ɨɛɥɚɞɚɟɬ ɧɟɫɤɨɥɶɤɢɦɢ ɜɚɠɧɵɦɢ ɩɪɟɢɦɭɳɟɫɬɜɚɦɢ ɩɟɪɟɞ myisamchk. Ʉɚɤ ɛɵɥɨ ɭɤɚɡɚɧɨ ɜɵɲɟ, ɭɬɢɥɢɬɚ mysqlcheck ɦɨɠɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɜ ɯɨɞɟ ɷɤɫɩɥɭɚɬɚɰɢɢ ɫɟɪɜɟɪɚ, ɩɪɢɱɟɦ ɞɚɠɟ ɜɨ ɜɪɟɦɹ ɨɛɫɥɭɠɢɜɚɧɢɹ ɡɚɩɪɨɫɨɜ. Ⱦɟɣɫɬɜɢɟ ɭɬɢɥɢɬɵ mysqlcheck ɪɚɫɩɪɨɫɬɪɚɧɹɟɬɫɹ ɧɚ ɰɟɥɵɟ ɛɚɡɵ ɞɚɧɧɵɯ, ɚ ɧɟ ɧɚ ɨɬɞɟɥɶɧɵɟ ɬɚɛɥɢɰɵ. Ⱦɥɹ ɜɵɡɨɜɚ mysqlcheck ɧɚ ɜɵɩɨɥɧɟɧɢɟ ɢɫɩɨɥɶɡɭɸɬɫɹ ɜ ɨɫɧɨɜɧɨɦ ɬɚɤɢɟ ɠɟ ɫɢɧɬɚɤɫɢɱɟɫɤɢɟ ɤɨɧɫɬɪɭɤɰɢɢ, ɤɚɤ ɢ ɞɥɹ ɜɵɡɨɜɚ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɝɨ ɫɪɟɞɫɬɜɚ mysqldump, ɡɚ ɨɞɧɢɦ ɢɫɤɥɸɱɟɧɢɟɦ: ɢɫɩɨɥɧɹɟɦɵɣ ɮɚɣɥ ɭɬɢɥɢɬɵ mysqlcheck ɦɨɠɧɨ ɫɤɨɩɢɪɨɜɚɬɶ ɢ ɨɛɨɡɧɚɱɢɬɶ ɞɪɭɝɢɦ ɢɦɟɧɟɦ, ɱɬɨɛɵ ɬɟɦ ɫɚɦɵɦ ɡɚɪɚɧɟɟ ɭɤɚɡɚɬɶ ɨɛɥɚɫɬɶ ɩɪɢɦɟɧɟɧɢɹ ɭɬɢɥɢɬɵ. ɍɬɢɥɢɬɚ ɨɩɪɟɞɟɥɹɟɬ, ɩɨɞ ɤɚɤɢɦ ɢɦɟɧɟɦ ɨɧɚ ɜɵɡɜɚɧɚ, ɢ ɞɟɣɫɬɜɭɟɬ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɦ ɨɛɪɚɡɨɦ. Ⱦɥɹ ɜɵɡɨɜɚ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɝɨ ɫɪɟɞɫɬɜɚ mysqlcheck ɧɚ ɜɵɩɨɥɧɟɧɢɟ ɩɪɢɦɟɧɹɟɬɫɹ ɨɞɢɧ ɢɡ ɫɥɟɞɭɸɳɢɯ ɫɩɨɫɨɛɨɜ: mysqlcheck [options] databasename table1 table2 table3 mysqlcheck [options] --databases database1 database2 mysqlcheck [options] --all-databases ɑɬɨɛɵ ɨɩɪɟɞɟɥɢɬɶ ɨɛɥɚɫɬɶ ɩɪɢɦɟɧɟɧɢɹ ɭɬɢɥɢɬɵ ɤɚɤ ɩɪɟɞɧɚɡɧɚɱɟɧɧɨɣ ɞɥɹ ɜɨɫɫɬɚɧɨɜɥɟɧɢɹ, ɚɧɚɥɢɡɚ ɢɥɢ ɨɩɬɢɦɢɡɚɰɢɢ ɛɚɡɵ ɞɚɧɧɵɯ, ɞɨɫɬɚɬɨɱɧɨ ɫɤɨɩɢɪɨɜɚɬɶ ɮɚɣɥ mysqlcheck ɩɨɞ ɢɦɟɧɟɦ mysqlrepair, mysqlanalyze ɢɥɢ mysqloptimize, ɚ ɡɚɬɟɦ ɜɵɡɵɜɚɬɶ ɷɬɢ ɮɚɣɥɵ ɨɛɵɱɧɵɦ ɨɛɪɚɡɨɦ, ɧɨ ɭɠɟ ɧɟ ɡɚɞɚɜɚɹ ɨɩɰɢɸ -r, -a ɢɥɢ -o. Ɍɚɤ, ɧɚɩɪɢɦɟɪ, ɱɬɨɛɵ ɜɨɫɫɬɚɧɨɜɢɬɶ ɜɫɟ ɛɚɡɵ ɞɚɧɧɵɯ, ɪɚɛɨɬɚɸɳɢɟ ɩɨɞ ɭɩɪɚɜɥɟɧɢɟɦ ɤɨɧɤɪɟɬɧɨɝɨ ɫɟɪɜɟɪɚ, ɞɨɫɬɚɬɨɱɧɨ ɜɜɟɫɬɢ ɫɥɟɞɭɸɳɭɸ ɤɨɦɚɧɞɭ: mysqlrepair -u root -p --all-databases Ʉɨɦɩɚɧɢɹ MySQL AB ɪɟɤɨɦɟɧɞɭɟɬ ɭɫɬɚɧɨɜɢɬɶ ɪɟɝɭɥɹɪɧɵɣ ɝɪɚɮɢɤ ɩɪɨɜɟɪɤɢ ɮɚɣɥɨɜ ɞɚɧɧɵɯ ɫ ɩɪɢɦɟɧɟɧɢɟɦ ɡɚɞɚɧɢɣ cron, ɚ ɧɚ ɷɬɚɩɟ ɡɚɩɭɫɤɚ ɫɟɪɜɟɪɚ MySQL ɤɚɠɞɵɣ ɪɚɡ ɜɵɡɵɜɚɬɶ ɧɚ ɜɵɩɨɥɧɟɧɢɟ ɨɞɧɭ ɢɡ ɭɤɚɡɚɧɧɵɯ ɭɬɢɥɢɬ. ɋɨɛɥɸɞɟɧɢɟ ɷɬɨɣ ɪɟɤɨɦɟɧɞɚɰɢɢ ɩɨɡɜɨɥɢɬ ɩɨɞɞɟɪɠɢɜɚɬɶ ɤɨɦɩɚɤɬɧɭɸ ɫɬɪɭɤɬɭɪɭ ɯɪɚɧɟɧɢɹ ɞɚɧɧɵɯ, ɫɩɨɫɨɛɫɬɜɭɸɳɭɸ ɭɫɤɨɪɟɧɢɸ ɨɩɟɪɚɰɢɣ ɱɬɟɧɢɹ; ɡɚɛɥɚɝɨɜɪɟɦɟɧɧɨ ɭɫɬɪɚɧɹɬɶ ɧɟɡɧɚɱɢɬɟɥɶɧɵɟ ɨɲɢɛɤɢ ɜ ɞɚɧɧɵɯ, ɤɨɬɨɪɵɟ ɦɨɝɭɬ ɫɨ ɜɪɟɦɟɧɟɦ ɩɪɢɜɟɫɬɢ ɤ ɫɟɪɶɟɡɧɵɦ ɩɪɨɛɥɟɦɚɦ; ɭɦɟɧɶɲɢɬɶ ɜɟɪɨɹɬɧɨɫɬɶ ɜɨɡɧɢɤɧɨɜɟɧɢɹ ɬɚɤɢɯ ɧɚɪɭɲɟɧɢɣ ɜ ɯɨɞɟ ɷɤɫɩɥɭɚɬɚɰɢɢ ɛɚɡɵ ɞɚɧɧɵɯ, ɤɨɬɨɪɵɟ ɦɨɝɥɢ ɛɵ ɩɨɜɥɢɹɬɶ ɧɚ ɪɚɛɨɬɭ ɩɨɥɶɡɨɜɚɬɟɥɟɣ. Ðåçþìå MySQL ɨɬɧɨɫɢɬɫɹ ɤ ɱɢɫɥɭ ɛɚɡ ɞɚɧɧɵɯ, ɨɛɟɫɩɟɱɢɜɚɸɳɢɯ ɧɚɢɛɨɥɟɟ ɩɪɨɫɬɨɟ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɟ. Ɉɫɜɨɟɧɢɟ ɧɚɜɵɤɨɜ ɪɚɛɨɬɵ ɫ ɷɬɨɣ ɛɚɡɨɣ ɞɚɧɧɵɯ ɦɨɠɟɬ ɩɪɢɧɟɫɬɢ ɪɚɡɪɚɛɨɬɱɢɤɚɦ PHP ɛɨɥɶɲɭɸ ɩɨɥɶɡɭ. ȼ ɩɨɫɥɟɞɧɟɟ ɜɪɟɦɹ ɩɪɨɰɟɞɭɪɚ ɢɧɫɬɚɥɥɹɰɢɢ MySQL ɧɚ ɦɧɨɝɢɯ ɩɥɚɬɮɨɪɦɚɯ ɡɧɚɱɢɬɟɥɶɧɨ ɭɩɪɨɫɬɢɥɚɫɶ. Ʉɪɨɦɟ ɬɨɝɨ, ɜ ɪɚɫɩɨɪɹɠɟɧɢɢ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢɦɟɟɬɫɹ ɲɢɪɨɤɢɣ ɩɟɪɟɱɟɧɶ Ãëàâà 14. Àäìèíèñòðèðîâàíèå áàçû äàííûõ MySQL 369 ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɯ ɫɪɟɞɫɬɜ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ ɫ ɝɪɚɮɢɱɟɫɤɢɦ ɢɧɬɟɪɮɟɣɫɨɦ ɢ ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ, ɩɪɟɞɧɚɡɧɚɱɟɧɧɵɯ ɞɥɹ ɩɪɨɫɦɨɬɪɚ ɫɬɪɭɤɬɭɪɵ ɛɚɡɵ ɞɚɧɧɵɯ, ɭɩɪɚɜɥɟɧɢɹ ɩɨɥɶɡɨɜɚɬɟɥɹɦɢ ɛɚɡɵ ɞɚɧɧɵɯ ɢ ɫɨɡɞɚɧɢɹ ɪɟɡɟɪɜɧɵɯ ɤɨɩɢɣ. Ⱥ ɱɬɨ ɤɚɫɚɟɬɫɹ ɛɨɥɟɟ ɫɥɨɠɧɵɯ ɡɚɞɚɱ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ, ɤ ɤɨɬɨɪɵɦ ɨɬɧɨɫɢɬɫɹ ɜɨɫɫɬɚɧɨɜɥɟɧɢɟ ɩɨɫɥɟ ɫɛɨɹ ɢ ɪɟɩɥɢɤɚɰɢɹ, ɬɨ ɛɚɡɚ ɞɚɧɧɵɯ MySQL ɩɨɡɜɨɥɹɟɬ ɪɟɲɚɬɶ ɨɛɟ ɷɬɢ ɡɚɞɚɱɢ ɩɪɟɞɟɥɶɧɨ ɩɪɨɫɬɨ. Ɉɞɧɚɤɨ ɜ ɩɨɫɥɟɞɧɟɟ ɜɪɟɦɹ ɩɪɨɢɡɨɲɥɢ ɫɟɪɶɟɡɧɵɟ ɢɡɦɟɧɟɧɢɹ, ɤɚɫɚɸɳɢɟɫɹ ɭɫɥɨɜɢɣ ɫɨɜɦɟɫɬɧɨɝɨ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɩɪɨɝɪɚɦɦɧɵɯ ɩɪɨɞɭɤɬɨɜ MySQL ɢ PHP. ȼ ɱɚɫɬɧɨɫɬɢ, ɢɡɦɟɧɢɥɢɫɶ ɩɪɢɧɰɢɩɵ ɥɢɰɟɧɡɢɪɨɜɚɧɢɹ, ɫɬɚɥɢ ɧɟɫɨɜɦɟɫɬɢɦɵɦɢ ɜɟɪɫɢɢ ɤɥɢɟɧɬɫɤɢɯ ɩɪɨɝɪɚɦɦ, ɜɵɩɭɳɟɧɨ ɧɨɜɨɟ ɪɚɫɲɢɪɟɧɢɟ mysqli ɢ ɩɨɹɜɢɥɚɫɶ ɩɨɞɞɟɪɠɤɚ ɬɪɚɧɡɚɤɰɢɣ. ɋ ɢɧɮɨɪɦɚɰɢɟɣ ɨɛ ɷɬɨɦ ɧɟɨɛɯɨɞɢɦɨ ɨɡɧɚɤɨɦɢɬɶɫɹ ɧɟ ɬɨɥɶɤɨ ɧɚɱɢɧɚɸɳɢɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ MySQL, ɧɨ ɢ ɩɨɥɶɡɨɜɚɬɟɥɹɦ ɫ ɛɨɥɶɲɢɦ ɫɬɚɠɟɦ. 370 ×àñòü II. PHP è MySQL