mysql µÄÈÕÖ¾µÄÆô¶¯Óë²é¿´
mysqlÓÐÒÔϼ¸ÖÖÈÕÖ¾£º ´íÎóÈÕÖ¾£º -log-err ²éѯÈÕÖ¾£º -log Âý²éѯÈÕÖ¾: -log-slow-queries ¸üÐÂÈÕÖ¾: -log-update ¶þ½øÖÆÈÕÖ¾£º -log-bin Ĭ ÈÏÇé¿öÏ£¬ËùÓÐÈÕÖ¾´´½¨ÓÚmysqldÊý¾ÝĿ¼ÖС£Í¨¹ýË¢ÐÂÈÕÖ¾£¬Äã¿ÉÒÔÇ¿ÖÆ mysqldÀ´¹Ø±ÕºÍÖØдò¿ªÈÕÖ¾Îļþ£¨»òÕßÔÚijЩÇé¿öÏÂÇл»µ½Ò»¸öеÄÈÕÖ¾£©¡£µ±ÄãÖ´ÐÐÒ»¸öFLUSH LOGSÓï¾ä»òÖ´ÐÐmysqladmin flush-logs»òmysqladmin refreshʱ£¬³öÏÖÈÕ־ˢР1. ´íÎóÈÕÖ¾ ÓÃ--log- error[=file_name]Ñ¡ÏîÀ´Ö¸¶¨mysqld±£´æ´íÎóÈÕÖ¾ÎļþµÄλÖá£Èç¹ûûÓиø¶¨file_nameÖµ£¬mysqldʹÓôíÎóÈÕÖ¾Ãû host_name.err ²¢ÔÚÊý¾ÝĿ¼ÖÐдÈëÈÕÖ¾Îļþ¡£Èç¹ûÄãÖ´ÐÐFLUSH LOGS£¬´íÎóÈÕÖ¾ÓÃ-oldÖØÐÂÃüÃûºó׺²¢ÇÒmysqld´´½¨Ò»¸öеĿÕÈÕÖ¾Îļþ¡£(Èç¹ûδ¸ø³ö--log-errorÑ¡ÏÔò²»»áÖØÐÂÃüÃû£©¡£ Èç¹û²»Ö¸¶¨--log-error£¬»òÕß(ÔÚWindowsÖÐ)Èç¹ûÄãʹÓÃ--consoleÑ¡Ï´íÎó±»Ð´Èë±ê×¼´íÎóÊä³östderr¡£Í¨³£±ê×¼Êä³öΪÄãµÄÖնˡ£ 2. ͨÓòéѯÈÕÖ¾ ÓÃ--log[=file_name]»ò-l [file_name]Ñ¡ÏîÆô¶¯Ëü¡£Èç¹ûûÓиø¶¨file_nameµÄÖµ£¬Ä¬ÈÏÃûÊÇhost_name.log¡£ 3. ÂýËÙ²éѯÈÕÖ¾ ÓÃ--log-slow-queries[=file_name]Ñ¡ÏîÆô¶¯Ê±£¬mysqld дһ¸ö°üº¬ËùÓÐÖ´ÐÐʱ¼ä³¬¹ýlong_query_timeÃëµÄSQLÓï¾äµÄÈÕÖ¾Îļþ.Èç¹ûûÓиø³öfile_nameÖµ£¬Ä¬ÈÏδÖ÷»úÃû£¬ºó׺Ϊ -slow.log¡£Èç¹û¸ø³öÁËÎļþÃû£¬µ«²»ÊǾø¶Ô·¾¶Ãû£¬ÎļþÔòдÈëÊý¾ÝĿ¼¡£ 3. ¸üÐÂÈÕÖ¾ ÓÃ--log-update[=file_name]Ñ¡ÏîÆô¶¯,²»ÍƼöʹÓÃ.
ÊÇ·ñÆôÓÃÁËÈÕÖ¾ mysql>show variables like 'log_%'; ÔõÑùÖªµÀµ±Ç°µÄÈÕÖ¾ mysql> show master status; ï@ʾ¶þßMÖÆÈÕÖ¾”µÄ¿ mysql> show master logs; ¿´¶þ½øÖÆÈÕÖ¾ÎļþÓÃmysqlbinlog shell>mysqlbinlog mail-bin.000001 »òÕßshell>mysqlbinlog mail-bin.000001 | tail ÔÚÅäÖÃÎļþÖÐÖ¸¶¨logµÄÝ”³öλÖÃ. Windows£ºWindows µÄÅäÖÃÎļþΪ my.ini£¬Ò»°ãÔÚ MySQL µÄ°²×°Ä¿Â¼Ï»òÕß c:\Windows Ï¡£ Linux£ºLinux µÄÅäÖÃÎļþΪ my.cnf £¬Ò»°ãÔÚ /etc Ï¡£ ÔÚlinuxÏ£º Sql´úÂë # ÔÚ[mysqld] ÖÐÝ”Èë #log log-error=/usr/local/mysql/log/error.log log=/usr/local/mysql/log/mysql.log long_query_time=2 log-slow-queries= /usr/local/mysql/log/slowquery.log # ÔÚ[mysqld] ÖÐÝ”Èë #log log-error=/usr/local/mysql/log/error.log log=/usr/local/mysql/log/mysql.log long_query_time=2 log-slow-queries= /usr/local/mysql/log/slowquery.log
windowsÏÂ: Sql´úÂë # ÔÚ[mysqld] ÖÐÝ”Èë #log log-error="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/error.log" log="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/mysql.log" long_query_time=2 log-slow-queries= "E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/slowquery.log" # ÔÚ[mysqld] ÖÐÝ”Èë #log log-error="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/error.log" log="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/mysql.log" long_query_time=2 log-slow-queries= "E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/slowquery.log"
¿ªÆôÂý²éѯ long_query_time =2 --ÊÇÖ¸Ö´Ðг¬¹ý¶à¾ÃµÄsql»á±»logÏÂÀ´£¬ÕâÀïÊÇ2Ãë log-slow-queries= /usr/local/mysql/log/slowquery.log --½«²éѯ·µ»Ø½ÏÂýµÄÓï¾ä½øÐмǼ log-queries-not-using-indexes = nouseindex.log --¾ÍÊÇ×ÖÃæÒâ˼£¬logÏÂÀ´Ã»ÓÐʹÓÃË÷ÒýµÄquery log=mylog.log --¶ÔËùÓÐÖ´ÐÐÓï¾ä½øÐмǼ windowsÏ¿ªÆômysqlÈÕÖ¾£º ÔÚ[mysql]ϼÓÈëÕâЩ£¨»ù±¾ÉϵÈÓÚ¼ÓÔÚ×îºóÃ棩£º log-error= #Enter a name for the query log file. Otherwise a default name will be used. #×¢:£¨Ð´³ÉtxtÎļþeditplus¿ÉÒÔ¼°Ê±ÖØÔØ,²»¹ýÓÐʱҪ·ÅÔÚCÅÌÏÂeditplus²Å¿ÉÒÔ¼°Ê±ÖØÔØ£© log= c:/mysql_query.log.txt #Enter a name for the slow query log file. Otherwise a default name will be used. log-slow-queries= #Enter a name for the update log file. Otherwise a default name will be used. log-update= #Enter a name for the binary log. Otherwise a default name will be used. log-bin= |