Check and Optimize MySQL Database Automatically with Crontab/Cron בדוק ייעל MySQL Database אוטומטית עם crontab / Cron
MySQL is a very popular free yet powerful database system. MySQL היא מערכת מאוד פופולרי באתר בחינם אך רב עוצמה. But even in great databases, the tables may get fragmented with overhead due to continuous update, or delete and insert operation on data stored in database. אבל גם במסדי נתונים גדולים, השולחנות עשויים לקבל מקוטעת עם תקורה בשל עדכון רציף, או למחוק ולהוסיף המבצע על הנתונים המאוחסנים באתר. Beside, it's also possibility that the databases may get corrupted. ליד, זה גם האפשרות כי מאגרי עשוי לקבל פגומה. Thus, performing health check on database and optimize MySQL server regularly is an important task. לכן, ביצוע בדיקת הבריאות על מסד הנתונים MySQL לייעל את השרת באופן קבוע היא משימה חשובה.
It's a bit troublesome if the database administrators have to login to the server or launching the phpMyAdmin to optimize the databases one by one or table by table manually. זה קצת בעייתי אם מנהלי מסדי נתונים צריך להתחבר לשרת או השקת phpMyAdmin לבצע אופטימיזציה של מסדי נתונים אחד אחד או שולחן ליד השולחן באופן ידני. Sometimes DB admin may simply forgets to do the job or set the frequency of optimization to lesser times. לפעמים מנהל DB אולי פשוט שוכח לעשות את העבודה או להגדיר את תדירות אופטימיזציה פעמים פחותה. It's recommended that every tables in MySQL databases are checked at least once a day on a busy server. מומלץ כי בכל הטבלאות במסדי נתונים MySQL נבדקות לפחות פעם ביום בשרת עסוק.
It's possible to automate the optimization of MySQL process by using crontab function in Linux/Unix/CentOS/FreeBSD. זה אפשרי להפוך את תהליך האופטימיזציה של MySQL באמצעות הפונקציה crontab ב Linux / Unix / CentOS / FreeBSD. The cron job to check and optimize MySQL databases can be created by using mysqlcheck client utility comes MySQL installation. את העבודה cron לבדוק לייעל את מסדי הנתונים MySQL ניתן ליצור באמצעות השירות ללקוח mysqlcheck מגיע ההתקנה MySQL. mysqlcheck client can checks, repairs, optimizes, and analyzes tables in MySQL database. הלקוח יכול mysqlcheck בדיקות, תיקונים, מייעל, ומנתח טבלאות במסד הנתונים MySQL.
To create a new cron job, login to the server as root or any other user, and then edit the crontab file (in most operating system, crontab -e will open crontab file in default text editor) to add in the following line of text. כדי ליצור עבודה חדשה cron, ההתחברות לשרת כמו שורש או כל משתמש אחר, ולאחר מכן לערוך את הקובץ crontab (בתוך מערכת ההפעלה ביותר, crontab-E יפתח את הקובץ crontab ברירת המחדל של עורך הטקסט) כדי להוסיף את השורה הבאה של טקסט . For users using cPanel, click on “Cron job” where you can set up crontab at daily, hourly and other interval. עבור משתמשים באמצעות cPanel, לחץ על "עבודה Cron" שבו אתה יכול להגדיר ב crontab יומי, לפי שעה ועוד הפסקה. Experience webmasters can also set up a crontab file in rc.hourly or rc.daily or other cron directory. חוויית מנהלי אתרים יכולים גם להגדיר קובץ crontab בספרייה cron rc.hourly או rc.daily או אחרים. Note that if you login as a MySQL or normal user with no access privileges to all database, it's not possible to optimize all databases, unless user ID and password for root is specified as in example below. שים לב שאם הכניסה כמו MySQL או המשתמש הרגיל ללא הרשאות גישה למסד הנתונים כל, זה לא אפשרי כדי למטב את כל מסדי הנתונים, אלא אם מזהה המשתמש ואת הסיסמה עבור השורש מוגדר כמו בדוגמה להלן.
0 1 * * * mysqlcheck -Aao –auto-repair -u root -p[password] > /dev/null 0 1 * * * mysqlcheck-Aao-Auto-תיקון השורש-u-p [סיסמה]> / dev / null
The above statement has the syntax similar to “mysqlcheck [options] –all-databases”, where –all-databases parameter is the default action is no databases is specified thus can be omitted. ההצהרה לעיל התחביר דומה mysqlcheck "[אפשרויות]-כל מסדי הנתונים", שבו כל-מסדי נתונים פרמטר היא פעולת ברירת המחדל היא לא מסדי נתונים מוגדר ולכן ניתן להשמט. The command will run mysqlcheck client to automatically analyze and optimize all databases at 1 am everyday. הפקודה יפעל הלקוח mysqlcheck מנתחים באופן אוטומטי כדי לייעל את כל מסדי הנתונים ב 1 היומיום. Note that there is not space between -p and your password for root. שים לב כי אין רווח בין-p והסיסמה שלך עבור השורש. You can change the running time to your preference, and also change the options for mysqlcheck command. באפשרותך לשנות את זמן הריצה ל ההעדפות שלך, וגם לשנות את האפשרויות עבור הפקודה mysqlcheck. If you just want to check and optimize certain databases or certain tables without the database, use the following syntax: אם אתה רק רוצה לבדוק ולבצע אופטימיזציה מסדי נתונים מסוימים או ללא טבלאות מסוימות בבסיס הנתונים, להשתמש בתחביר הבא:
mysqlcheck [options] db_name [tables] mysqlcheck [נוספות] db_name [טבלאות]
mysqlcheck [options] –databases DB1 [DB2 DB3...] mysqlcheck [אפשרויות] מסדי-DB1 [DB2 DB3 ...]
You may want to remove –auto-repair switch from the above command, as a table repair operation might cause data loss under some circumstances the operation due to causes include but are not limited to filesystem errors. ייתכן שתרצה להסיר-Auto-מתג לתיקון הפקודה מן האמור לעיל, כמו פעולת תיקון השולחן עלול לגרום לאובדן נתונים בנסיבות מסוימות את הניתוח בשל סיבות כוללים אך אינם מוגבלים שגיאות במערכת הקבצים. For those who has changed the character set and collation of MySQL databases may also need to use –default-character-set option. לאלה אשר שינתה את ערכת התווים ואת איסוף של מסדי נתונים MySQL ייתכן שתצטרך להשתמש ב-default-תו-אפשרות להגדיר. More information on all available switches and options available can be found מידע נוסף על הבוררים הזמינים של כל האפשרויות הקיימות ניתן למצוא here כאן . .
IMPORTANT : The page is machine translated and provided "as is" without warranty. חשוב: הדף מכונת תירגם מתפרסם "כמות שהוא" ללא אחריות. Machine translation may be difficult to understand. תרגום מכונה יכול להיות קשה להבין. Please refer to נא עיין original English article המאמר המקורי באנגלית whenever possible. בכל הזדמנות אפשרית.
Related Articles מאמרים קשורים
- How to Disable Linux and Unix Cron Jobs (Crontab) Email Sending איך השבת Linux ו-Unix Cron Jobs (crontab) שליחת דוא"ל
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL Database Performance Tuning Best Practices Video Tutorial
- Enable Logging of Slow Queries (Slow Query Log) in MySQL Database הפעל רישום של שאילתות איטי (Slow Query Log) ב-MySQL Database
- How to Find and Replace Text in MySQL Database using SQL כיצד לחפש ולהחליף טקסט ב-MySQL מסד נתונים באמצעות SQL
- Change and Reset MySQL root Password שינוי סיסמה איפוס שורש MySQL
- Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 – Part 3 התקנת שרת אינטרנט ב FreeBSD 6.0 עם Apache 2.2, MySQL 5.0 ו-PHP 5 - חלק 3
- Remove or Trim First or Last Few Characters in MySQL Database with SQL להסיר או חתוך ראשית או דמויות האחרונים MySQL Database עם SQL
- How to Backup and Restore (Export and Import) MySQL Databases Tutorial כיצד גיבוי ושחזור (ייצוא וייבוא) MySQL Databases Tutorial
- Reset the Root Password of MySQL Server איפוס סיסמה השורש של MySQL Server
- Using phpMyAdmin for Effective MySQL Management in Windows XP השימוש ב phpMyAdmin MySQL עבור ניהול אפקטיבי ב-Windows XP










































August 13th, 2009 22:33 13 אוגוסט 2009 22:33
Thanks!!, I'll test it on my testing server. תודה!, אני מוכן לבדוק אותו על שרת בדיקה שלי.
April 2nd, 2009 09:41 2 אפריל 2009 09:41
I'ma newby on managing MySQL. Newby I'ma על ניהול MySQL.
I want to ask you, how to to make sure if the Cron is working? אני רוצה לשאול אותך, איך לוודא אם Cron הוא עובד?
Thanks תודה
November 16th, 2008 12:48 16 נובמבר 2008 12:48
along the lines of what Zubin is suggesting you can use the –silent(-s) switch as well, so you only get output if there is an error, something like לאורך שורות של זובין מה מציע אתה יכול להשתמש-אילם (-s) הבורר כמו גם, כך אתה מקבל פלט אם יש שגיאה, משהו כמו
MAILTO=email@domain.com Mailto = email@domain.com
0 1 * * * mysqlcheck -Aaos -uroot -ppassword 0 1 * * * mysqlcheck-Aaos-uroot-ppassword
this way you will only get an email if there is an error ככה אתה רק ילך דוא"ל אם יש שגיאה
September 20th, 2008 18:34 20 ספטמבר 2008 18:34
Sure mysql does need frequent tunning, and also I have seen a lot of the servers running in the default configuration. MySQL בטח אין צורך tunning תכופים, וגם ראיתי הרבה השרתים רצים בתצורת ברירת המחדל. which happens to be a very modest one. שבמקרה אחד צנוע מאוד. If you have access to the mysql configuration file, there are some values that can make your server breathe more often. אם יש לך גישה לקובץ התצורה MySQL, יש כמה ערכים אשר יכול לגרום לשרת שלך לנשום לעתים קרובות יותר. And make your visitors more happy. ולעשות המבקרים שלך יותר מאושרים.
May 6th, 2008 19:15 6 מאי 2008 19:15
I did not know that it was nesessary to perform a regular check for mysql. לא ידעתי שזה nesessary לבצע בדיקה קבועה MySQL.
January 16th, 2008 06:40 16 ינואר 2008 06:40
Note that -–auto-repair should have two dashes שים לב - Auto-צריך לתקן שני מקפים
Also, you might want to leave “> /dev/null” out for the first few runs, to see the results of the command (if you put MAILTO=me@mydomain.com at the top of the crontab, the results will get sent there). כמו כן, מומלץ להשאיר "> / dev / null" החוצה עבור רץ הראשונים, כדי לראות את התוצאות של הפקודה (אם תשימו mailto = me@mydomain.com בראש crontab, את התוצאות יקבל נשלח לשם).