Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In general_log file i have queries:

160806  9:53:26      11 Connect     dbname@localhost on 
     11 Query       SET NAMES utf8
     11 Query       SET character_set_client="utf8"
     11 Query       SET character_set_connection="utf8"
     11 Query       SET character_set_database="utf8"
     11 Query       SET character_set_results="utf8"
     11 Query       SET character_set_server="utf8"
     11 Query       SET character_set_system="utf8"
     11 Init DB     dbname

Is that possible to make 1 query instead of 7 queries? Will it speed up significantly?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
156 views
Welcome To Ask or Share your Answers For Others

1 Answer

See if I am currently capturing traffic with the General Log:

SELECT @@general_log;   -- 1 if capturing, 0 if not
-- for me, a 1. This means I have been capturing (good for development. Poor idea for Production)

SELECT @@general_log_file; -- file name for General Log if capturing.
-- for me: GeneralLogBegin_20160803_1420.log

SELECT @@datadir; -- the location of the general_log, and other logs
-- for me: C:ProgramDataMySQLMySQL Server 5.6Data

Now I turn off the capturing of the General Log below, because mine was capturing:

SET GLOBAL general_log=0; -- stop logging

I MOVE my log file to a backup directory, renaming it to GL_from_20160803_1420_to_20160806_1559

There is little ambiguity to the content and datetime range of capture that the above file embodies.

Set the new name for the log file capture (Begin segment for filename)

SET GLOBAL general_log_file='GeneralLogBegin_20160806_1559.log';
SET GLOBAL general_log=1; -- Start logging again

Run an app of mine that connects to the server, and General Log contains:

ChunkA:

160806 16:08:37   170 Connect   MrSmithers@www.xxx.yyy.zzz on stackoverflow
          170 Query SHOW VARIABLES
          170 Query SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP())
          170 Query SHOW COLLATION
          170 Query SET NAMES latin1
          170 Query SET character_set_results=NULL
          170 Init DB   my_db_name

Note: you may need to do

mysqladmin -u root -p flush-log

(prompted for password) in order to flush the logs from cache to the file. By the way, Sublime Text is awesome for auto-refresh of a text file currently loaded. Such as, a log file.

So my ChunkA above is the connection stub of a new connection coming in. It is driven by the commands of the program in use, whatever that may be. It is prior to your program commands that you are used to and code. If you are continuously creating new connections, executing code you write, and disconnecting, well these are all part of the baggage. You are not in control of optimizing them in any simple fashion.

What you should consider doing is turning OFF the General Query log in a production environment. And only enabling it during Debug and Test environment settings. Having it on increases unnecessary burden on you stack.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...